how to use StgOpenStorageEx
Hi all,
when i use StgOpenStorageEx(L"C:\\myfile.xml", .... ), it work well
but i use StgOpenStorageEx( lpszWFile, ), not work (see code below)
any idea? i convert CString to WCHAR incorrect?
void changeInfo(CString sFileName)
{
IPropertySetStorage *pPropSetStg = NULL;
IPropertyStorage *pPropStg = NULL;
PROPSPEC propspec;
PROPVARIANT propWrite;
PROPVARIANT propRead;
HRESULT hr = S_OK;
WCHAR* lpszWFile = new WCHAR[MAX_PATH];
CFile cFile;
if ( cFile.Open(sFileName, CFile::modeRead) )
{
sFileName = cFile.GetFilePath();
cFile.Close();
}
else
return;
LPTSTR lpStr = sFileName.GetBuffer( sFileName.GetLength() );
int nLen = MultiByteToWideChar(CP_ACP, 0,lpStr, -1, NULL, NULL);
MultiByteToWideChar(CP_ACP, 0, lpStr, -1, lpszWFile, nLen);
// Open a file and a property set within it.
hr = StgOpenStorageEx( lpszWFile,//L"C:\\myfile.xml",
STGM_DIRECT|STGM_SHARE_EXCLUSIVE|STGM_READWRITE,
STGFMT_ANY,
// STGFMT_STORAGE //Structured Storage property sets
// STGFMT_FILE //NTFS file system property sets
0,
NULL,
NULL,
IID_IPropertySetStorage,
reinterpret_cast<void**>(&pPropSetStg) );
sFileName.ReleaseBuffer();
delete[] lpszWFile;
DWORD Result = 0;
if( FAILED(hr) )
{
Result = GetLastError();
//throw L"Failed StgOpenStorageEx";
return;
}