int IsExcel9(WCHAR *wcFilename) {
// Open document as an OLE compound document...
HRESULT hr;
IStorage *pStg = 0;
hr = ::StgOpenStorage(wcFilename, 0, STGM_READWRITE | STGM_SHARE_EXCLUSIVE, 0, 0, &pStg);
if(FAILED(hr)) return 0;
// Now, get the Workbook stream
IStream *pStm;
WCHAR *wcBookStm = L"Workbook";
hr = pStg->OpenStream(wcBookStm, 0, STGM_READWRITE | STGM_SHARE_EXCLUSIVE , 0, &pStm);
if(FAILED(hr)) {
pStg->Release();
return 0;
}
char buf[32000];
DWORD dwRead;
short id, len;
for(;;) {
// Read id & len first...
HRESULT hr = pStm->Read(&id, 2, &dwRead);
if( (FAILED(hr)) || (dwRead != 2) ) break;
pStm->Read(&len, 2, &dwRead);
if(dwRead != 2) break;
if((id == 0) && (len == 0)) break;
// Check for XL9File record
if(id == 0x1c0) {
pStm->Release();
pStg->Release();
return 1;
}
// Eat record...
if(len > 32000) len = 32000;
pStm->Read(buf, (long)len, &dwRead);
if((DWORD)len != dwRead) break;
}
// Cleanup
pStm->Release();
pStg->Release();
return 0;
}