PRB: Attachment Size Is Corrupted by Multiple Writes to Attachment Stream (820721)



The information in this article applies to:

  • Microsoft SmartPhone 2002 SDK
  • Microsoft Windows CE Platform SDK for Pocket PC 2002

SYMPTOMS

Multiple writes to an attachment stream corrupt the attachment size.

CAUSE

The calculation for attachment size does not work if Seek is used with STREAM_SEEK_END instead of STREAM_SEEK_SET.

RESOLUTION

To resolve the problem, follow these steps:
  1. Read the size of the attachment stream by using the Stat method of IStream.
  2. Use the size that is returned in LARGE_INTEGER to seek to the end of the stream by using STREAM_SEEK_SET on the attachment stream.
  3. Write to the stream.

STATUS

Microsoft has confirmed that this is a problem in the Microsoft products that are listed at the beginning of this article.

MORE INFORMATION

The following code sample shows how to seek to the end of stream and then write to it:
 
//If they are not already included, you may need these header files.
#include <initguid.h>
#include <coguid.h>

 STATSTG statstg;
 LARGE_INTEGER liOffset ;

 hr = pAttach->OpenProperty(PR_ATTACH_DATA_BIN, &IID_IStream,STGM_WRITE, MAPI_MODIFY , (LPUNKNOWN *) &pStreamAttachment);	

 hr = pStreamAttachment->Stat(&statstg,STATFLAG_NONAME); 

 liOffset.QuadPart = statstg.cbSize.QuadPart;

 hr = pStreamAttachment->Seek(liOffset, STREAM_SEEK_SET , NULL); 

 if (FAILED(hr)) goto Cleanup;

 pStreamAttachment->Write(...);
 pStreamAttachment->Commit(STGC_DEFAULT);
 pStreamAttachment->Release();

	

Modification Type:MajorLast Reviewed:9/24/2003
Keywords:kbprb KB820721 kbAudDeveloper