Click here to Skip to main content
15,884,986 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: Error "string data,right truncated" generate when trying to Update by CRecordset? Pin
Le@rner3-Nov-10 19:34
Le@rner3-Nov-10 19:34 
AnswerRe: Error "string data,right truncated" generate when trying to Update by CRecordset? Pin
David Crow4-Nov-10 3:01
David Crow4-Nov-10 3:01 
QuestionInterlockedCompareExchange/cmpxchg-lock free queue Pin
Endaroza3-Nov-10 11:53
Endaroza3-Nov-10 11:53 
AnswerRe: InterlockedCompareExchange/cmpxchg-lock free queue Pin
Electron Shepherd3-Nov-10 13:52
Electron Shepherd3-Nov-10 13:52 
GeneralRe: InterlockedCompareExchange/cmpxchg-lock free queue [modified] Pin
Endaroza3-Nov-10 22:03
Endaroza3-Nov-10 22:03 
GeneralRe: InterlockedCompareExchange/cmpxchg-lock free queue Pin
federico.strati3-Nov-10 23:47
federico.strati3-Nov-10 23:47 
AnswerSolved !###$@#$ Pin
Endaroza4-Nov-10 0:01
Endaroza4-Nov-10 0:01 
QuestionFind Count Of Bytes Written To An IStream [modified] Pin
Frederick J. Harris3-Nov-10 8:38
Frederick J. Harris3-Nov-10 8:38 
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;                              //==
                                     // 4



The 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 = 4

i       idx.dwPlotRecord        pcbWritten
=========================================
1       1                       4
2       3                       4
3       4                       4
4       5                       4


After 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 past the original 16 byte IStream::Write()...

//CmpStr08  -- 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\\CmpStr08\\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_SIMPLE | 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\CmpStr08\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


modified on Wednesday, November 3, 2010 4:36 PM

AnswerRe: Find Count Of Bytes Written To An IStream Pin
Electron Shepherd3-Nov-10 11:34
Electron Shepherd3-Nov-10 11:34 
GeneralRe: Find Count Of Bytes Written To An IStream Pin
Frederick J. Harris3-Nov-10 13:45
Frederick J. Harris3-Nov-10 13:45 
AnswerRe: Find Count Of Bytes Written To An IStream Pin
Frederick J. Harris4-Nov-10 4:23
Frederick J. Harris4-Nov-10 4:23 
QuestionHow can use Time Out for any function or thread? Pin
Le@rner3-Nov-10 2:30
Le@rner3-Nov-10 2:30 
AnswerRe: How can use Time Out for any function or thread (URL checker) Pin
Moak3-Nov-10 2:44
Moak3-Nov-10 2:44 
AnswerRe: How can use Time Out for any function or thread? Pin
David Crow3-Nov-10 3:17
David Crow3-Nov-10 3:17 
AnswerRe: How can use Time Out for any function or thread? Pin
yu-jian8-Nov-10 15:21
yu-jian8-Nov-10 15:21 
Questionhow to generate uid for header files Pin
lakshman rao3-Nov-10 2:22
lakshman rao3-Nov-10 2:22 
AnswerRe: how to generate uid for header files Pin
Cedric Moonen3-Nov-10 2:29
Cedric Moonen3-Nov-10 2:29 
AnswerRe: how to generate uid for header files PinPopular
CPallini3-Nov-10 2:50
mveCPallini3-Nov-10 2:50 
AnswerRe: how to generate uid for header files Pin
«_Superman_»3-Nov-10 6:17
professional«_Superman_»3-Nov-10 6:17 
GeneralRe: how to generate uid for header files Pin
lakshman rao8-Nov-10 2:56
lakshman rao8-Nov-10 2:56 
AnswerRe: how to generate uid for header files Pin
yu-jian4-Nov-10 15:20
yu-jian4-Nov-10 15:20 
QuestionNumber of instances running Pin
ganesh.dp2-Nov-10 23:53
ganesh.dp2-Nov-10 23:53 
AnswerRe: Number of instances running Pin
GAJERA3-Nov-10 0:42
GAJERA3-Nov-10 0:42 
AnswerRe: Number of instances running Pin
ShilpiP3-Nov-10 1:58
ShilpiP3-Nov-10 1:58 
AnswerRe: Number of instances running Pin
Sauro Viti3-Nov-10 3:55
professionalSauro Viti3-Nov-10 3:55 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.