I am trying to create a memory card in Windows using VS2010. I am doing this in a DLL. The first DLL instance matches the file just fine. The second instance inside the same process calls
*ppvData = ::MapViewOfFile( *phMapping, FILE_MAP_READ, 0, 0, 0 );
with the error "Out of memory for this command." I do not know why this is happening.
If I match 2 different files instead of two identical files, everything works fine, so I donβt trust the "Out of memory" error message.
Thanks.
hr = MapFile(sPath, &m_hVoiceData, &m_pVoiceData,wsErr ); HRESULT CTTSEngObj::MapFile( wstring uPath, // Value that contains file path HANDLE * phMapping, // Pointer to file mapping handle void ** ppvData, // Pointer to the data wstring &uError) { HRESULT hr = S_OK; CSpDynamicString dstrFilePath(uPath.c_str()); if ( SUCCEEDED( hr ) ) { bool fWorked = false; *phMapping = NULL; *ppvData = NULL; HANDLE hFile; #ifdef _WIN32_WCE hFile = CreateFileForMapping( dstrFilePath, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL ); #else hFile = CreateFile(CW2T(dstrFilePath), GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL ); #endif if (hFile != INVALID_HANDLE_VALUE) { *phMapping = ::CreateFileMapping( hFile, NULL, PAGE_READONLY, 0, 0, NULL ); if (*phMapping) { *ppvData = ::MapViewOfFile( *phMapping, FILE_MAP_READ, 0, 0, 0 ); if (*ppvData) { fWorked = true; } else { uError=GetLastErrorStdStrW(); } } else { uError=L"mapfile: fm failed"; } ::CloseHandle( hFile ); } else { uError=L"mapfile: invalidhandle"; } if (!fWorked) { hr = HRESULT_FROM_WIN32(::GetLastError()); if (*phMapping) { ::CloseHandle(*phMapping); *phMapping = NULL; } } } else { uError=L"mapfile: dynstr"; } return hr; } /* CTTSEngObj::MapFile */
And here is how it is declared:
class ATL_NO_VTABLE CTTSEngObj : public CComObjectRootEx<CComMultiThreadModel>, public CComCoClass<CTTSEngObj, &CLSID_SampleTTSEngine>, public ISpTTSEngine, public ISpObjectWithToken { private: CComPtr<ISpObjectToken> m_cpToken; HANDLE m_hVoiceData; void* m_pVoiceData;