Hi Jose!
I just dug up the code I was working with a couple weeks ago that pretty concisely demonstrates the problem. I've just glanced through your post above quiuckly and am going to examine it in more detail after I post this. Itsounds like you have some ideas there that might as you say be a work around. Anyway, this code is unfortunately C++, but I'm sure you'll understand it. I call the IStream::Stat method to get the cbSize data which is quite awkward in C/C++ due to the LARGE_INTEGER struct (PB makes this much easier!!!!). The particular IStream I previously wrote 16 bytes into, i.e., four four byter integers. The Index struct just has one four byte member. I arbitrarily ran the loop up to 8 and you can see the output. Disheartingly, pcbRead comes out with '4' for all reads - even beyond the end of the IStream (only first four are ledgitimate). S_OK was returned for all reads (even beyond end). And of course cbSize returned 4096. When I saw this all I could say/think was WOW! THIS IS A PROBLEM!
//CmpStr10 -- compiled as C++
#include <objbase.h>
#include <stdio.h>
#include <string.h>
typedef struct tagINDEX
{
DWORD dwPlotRecord; // 4
}INDEX; //==
// 4
int main(void)
{
wchar_t szFile[]=L"C:\\Code\\VStudio\\VC++6\\Projects\\COM\\CompStor\\CmpStr07\\Release\\Data.dat";
IStream* pIdxStream=NULL;
IStorage* pStorage=NULL;
char szBuffer[128];
ULONG pcbRead=0;
DWORD grfMode;
STATSTG sts;
unsigned i;
HRESULT hr;
INDEX idx;
wprintf(L"szFile = %s\n",szFile);
grfMode=STGM_DIRECT | STGM_READ | STGM_SHARE_EXCLUSIVE;
hr=StgOpenStorage(szFile,NULL,grfMode,NULL,0,&pStorage);
if(SUCCEEDED(hr))
{
printf("StgOpenStorage() Succeeded!\n");
hr=pStorage->OpenStream(L"Index", NULL, STGM_READ | STGM_SHARE_EXCLUSIVE, 0, &pIdxStream);
if(SUCCEEDED(hr))
{
printf("pStorage->OpenStream(Index) Succeeded!\n");
hr=pIdxStream->Stat(&sts,1);
if(SUCCEEDED(hr))
{
printf("pIdxStream->Stat(&sts,1) Succeeded!\n");
printf("sts.cbSize.LowPart = %u\n",sts.cbSize.LowPart);
printf("sts.cbSize.HighPart = %u\n",sts.cbSize.HighPart);
}
printf("\ni\tpcbRead\tidx.dwPlotRecord\tHRESULT\n");
printf("===============================================\n");
for(i=1; i<=8; i++)
{
hr=pIdxStream->Read(&idx,sizeof(INDEX),&pcbRead);
switch(hr)
{
case S_OK:
strcpy(szBuffer,"S_OK");
break;
case S_FALSE:
strcpy(szBuffer,"S_FALSE");
break;
default:
strcpy(szBuffer,"Don't Know What hr Means!");
break;
}
printf("%u\t%u\t%u\t\t\t%s\n",i,pcbRead,idx.dwPlotRecord,szBuffer);
}
pIdxStream->Release();
}
pStorage->Release();
}
getchar();
return 0;
}
/*
szFile = C:\Code\VStudio\VC++6\Projects\COM\CompStor\CmpStr07\Release\Data.dat
StgOpenStorage() Succeeded!
pStorage->OpenStream(Index) Succeeded!
pIdxStream->Stat(&sts,1) Succeeded!
sts.cbSize.LowPart = 4096
sts.cbSize.HighPart = 0
i pcbRead idx.dwPlotRecord HRESULT
===============================================
1 4 1 S_OK
2 4 3 S_OK
3 4 4 S_OK
4 4 5 S_OK
5 4 0 S_OK
6 4 0 S_OK
7 4 0 S_OK
8 4 0 S_OK
*/