0

I need to check if a in memory buffer BYTE* lpBuf contain data of a stucture storage file data.

Currently I save the buffer data into a temp file, then use StgOpenStorage to open the file. If the open succeeds, then the file is a structured storage file, otherwise it is not.

CFile File;

if (File.Open(_T("E:\\Myfile.dat"), CFile::modeCreate | CFile::modeRead)
{
  File.Write(lpBuf, uBufSize);
  File.Close();
}

LPSTORAGE lpStorageFile = NULL;

HRESULT hr = StgOpenStorage(_T("E:\\Myfile.dat"), NULL, STGM_TRANSACTED | STGM_READ | STGM_SHARE_EXCLUSIVE, NULL, 0, &lpStorageFile);

return SUCCEED(hr);

Is there any easy way to do the task?

Thanks

alancc
  • 487
  • 2
  • 24
  • 68
  • You would favor StgIsStorageFile() to do this test, avoids the leak. Avoid the file with StgIsStorageILockBytes(), created with CreateILockBytesOnHGlobal(). – Hans Passant Jan 10 '20 at 23:34
  • My data is stored in BYTE* lpBuf, not in hGlobal created by GlobalAlloc. In such a case, CreateLockBytesOnHGlobal() seems to not workable for the case? – alancc Jan 11 '20 at 01:07

0 Answers0