Find Count Of Bytes Written To An IStream [modified]
-
This is a basic COM Compound Document or Structured Storage question. I created an IStream within an IStorage and wrote four of these (each four bytes) to that IStream…
typedef struct tagINDEX
{
DWORD dwPlotRecord; // 4
}INDEX; //==
// 4The Storage was created like so…
wchar_t szFile[]=L"C:\\Code\\VStudio\\VC++6\\Projects\\COM\\CompStor\\CmpStr07\\Release\\Data.dat";
IStorage* pStorage=NULL;
DWORD grfMode;
HRESULT hr;grfMode=STGM_SIMPLE | STGM_CREATE | STGM_READWRITE | STGM_SHARE_EXCLUSIVE ;
hr=StgCreateDocfile(szFile,grfMode,0,&pStorage);I can read those four records out of my IStream using IStream::Read() but have been unable to determine the correct byte count of the four records (each four bytes) I wrote in with IStream::Write(). Since each INDEX record is four bytes and I wrote four such records ‘in’, then I’d hope to obtain an…
IStream::Stat(STATSTG*, STATFLAG_NONAME)
…return where the STATSTG.cbSize.LowPart would equal 16. This is not what is returned to me, but rather the number 4096, which looks suspiciously to me like a sector size, which I’m further assumming was the initial memory/file allocation for the IStream. It does not appear to me that Streams have an analogous function to the Windows Base Services GetFileSize() Api. Does anyone know anything about this? How do you get the number of bytes actually written to a Stream as opposed to the total allocation for the Stream? I'm just teaching myself COM Compound Document Storage Interfaces, and was doing rather well until I hit this problem! I'll provide some additional information. Here is what got written into a Simple IStream...
Now Try To Put Data In Structured Storage!
szFile = C:\Code\VStudio\VC++6\Projects\COM\CompStor\CmpStr07\Release\Data.dat
StgCreateDocFile() Succeeded!
pStorage->CreateStream(Index) Succeeded!
Will Now Try To Write Index Records To Structured Storage
dwNumPlots = 4i idx.dwPlotRecord pcbWritten
1 1 4
2 3 4
3 4 4
4 5 4After having written those 16 bytes and Releasing() both pStream and pStorage, then re-opening both, that's where I ran into the difficulty. Here is a short program with output afterward showing that even S_OK is returned by reading pa
-
This is a basic COM Compound Document or Structured Storage question. I created an IStream within an IStorage and wrote four of these (each four bytes) to that IStream…
typedef struct tagINDEX
{
DWORD dwPlotRecord; // 4
}INDEX; //==
// 4The Storage was created like so…
wchar_t szFile[]=L"C:\\Code\\VStudio\\VC++6\\Projects\\COM\\CompStor\\CmpStr07\\Release\\Data.dat";
IStorage* pStorage=NULL;
DWORD grfMode;
HRESULT hr;grfMode=STGM_SIMPLE | STGM_CREATE | STGM_READWRITE | STGM_SHARE_EXCLUSIVE ;
hr=StgCreateDocfile(szFile,grfMode,0,&pStorage);I can read those four records out of my IStream using IStream::Read() but have been unable to determine the correct byte count of the four records (each four bytes) I wrote in with IStream::Write(). Since each INDEX record is four bytes and I wrote four such records ‘in’, then I’d hope to obtain an…
IStream::Stat(STATSTG*, STATFLAG_NONAME)
…return where the STATSTG.cbSize.LowPart would equal 16. This is not what is returned to me, but rather the number 4096, which looks suspiciously to me like a sector size, which I’m further assumming was the initial memory/file allocation for the IStream. It does not appear to me that Streams have an analogous function to the Windows Base Services GetFileSize() Api. Does anyone know anything about this? How do you get the number of bytes actually written to a Stream as opposed to the total allocation for the Stream? I'm just teaching myself COM Compound Document Storage Interfaces, and was doing rather well until I hit this problem! I'll provide some additional information. Here is what got written into a Simple IStream...
Now Try To Put Data In Structured Storage!
szFile = C:\Code\VStudio\VC++6\Projects\COM\CompStor\CmpStr07\Release\Data.dat
StgCreateDocFile() Succeeded!
pStorage->CreateStream(Index) Succeeded!
Will Now Try To Write Index Records To Structured Storage
dwNumPlots = 4i idx.dwPlotRecord pcbWritten
1 1 4
2 3 4
3 4 4
4 5 4After having written those 16 bytes and Releasing() both pStream and pStorage, then re-opening both, that's where I ran into the difficulty. Here is a short program with output afterward showing that even S_OK is returned by reading pa
Frederick J. Harris wrote:
How do you get the number of bytes actually written to a Stream as opposed to the total allocation for the Stream?
I'm not sure you can. I've just looked at the source for an MMC snap-in we have, and that uses streams to store and retrieve the console state. We needed to store some binary data, so we wrote out the length of the data, as a four-byte long, and then the data itself. On reading, we read the first four bytes (which we know will be there), and then use that to determine how much more data to read.
-
Frederick J. Harris wrote:
How do you get the number of bytes actually written to a Stream as opposed to the total allocation for the Stream?
I'm not sure you can. I've just looked at the source for an MMC snap-in we have, and that uses streams to store and retrieve the console state. We needed to store some binary data, so we wrote out the length of the data, as a four-byte long, and then the data itself. On reading, we read the first four bytes (which we know will be there), and then use that to determine how much more data to read.
Thanks for the feedback Electron. Been mulling over the problem and it occurred to me I may not be able to use the STGM_SIMPLE flag in the STGM parameter, but may need to use the full transacted mode (with ::Commit() to get record counts to work. I'll read up on it this evening, and maybe try it again tomorrow. It would be neat to get this to work. If structured storage has this limitation, its going to be useless to me. I'm not ready to give up just yet though. :)
-
This is a basic COM Compound Document or Structured Storage question. I created an IStream within an IStorage and wrote four of these (each four bytes) to that IStream…
typedef struct tagINDEX
{
DWORD dwPlotRecord; // 4
}INDEX; //==
// 4The Storage was created like so…
wchar_t szFile[]=L"C:\\Code\\VStudio\\VC++6\\Projects\\COM\\CompStor\\CmpStr07\\Release\\Data.dat";
IStorage* pStorage=NULL;
DWORD grfMode;
HRESULT hr;grfMode=STGM_SIMPLE | STGM_CREATE | STGM_READWRITE | STGM_SHARE_EXCLUSIVE ;
hr=StgCreateDocfile(szFile,grfMode,0,&pStorage);I can read those four records out of my IStream using IStream::Read() but have been unable to determine the correct byte count of the four records (each four bytes) I wrote in with IStream::Write(). Since each INDEX record is four bytes and I wrote four such records ‘in’, then I’d hope to obtain an…
IStream::Stat(STATSTG*, STATFLAG_NONAME)
…return where the STATSTG.cbSize.LowPart would equal 16. This is not what is returned to me, but rather the number 4096, which looks suspiciously to me like a sector size, which I’m further assumming was the initial memory/file allocation for the IStream. It does not appear to me that Streams have an analogous function to the Windows Base Services GetFileSize() Api. Does anyone know anything about this? How do you get the number of bytes actually written to a Stream as opposed to the total allocation for the Stream? I'm just teaching myself COM Compound Document Storage Interfaces, and was doing rather well until I hit this problem! I'll provide some additional information. Here is what got written into a Simple IStream...
Now Try To Put Data In Structured Storage!
szFile = C:\Code\VStudio\VC++6\Projects\COM\CompStor\CmpStr07\Release\Data.dat
StgCreateDocFile() Succeeded!
pStorage->CreateStream(Index) Succeeded!
Will Now Try To Write Index Records To Structured Storage
dwNumPlots = 4i idx.dwPlotRecord pcbWritten
1 1 4
2 3 4
3 4 4
4 5 4After having written those 16 bytes and Releasing() both pStream and pStorage, then re-opening both, that's where I ran into the difficulty. Here is a short program with output afterward showing that even S_OK is returned by reading pa
I've studied up on the issue enough to have convinced myself that any further effort to use any system capabilities to determine the count of bytes previously written to an IStream would be fruitless. While Microsoft's documentation does push the analogy that IStreams are pretty much like files, the fact is that the analogy only goes so far. It appears that some file capabilities don't exist for IStreams in compound storage, and I'd guess at this point marking the end of written bytes is one of them. It follows from this that there is nothing akin to a SetEndOfFile(). It occurs to me that these missing capabilities could be coded into an app that uses compound document files, for example creating a seperate IStream to store the actual length of data written into other IStreams.