Microsoft KB Archive/820721

= PRB: Attachment Size Is Corrupted by Multiple Writes to Attachment Stream =

Article ID: 820721

Article Last Modified on 9/24/2003

-

APPLIES TO


 * Microsoft SmartPhone 2002 SDK
 * Microsoft Windows CE Platform Software Development Kit for Handheld PC 2000

-



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.
 * 1) include 
 * 2) include 

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;

Additional query words: IAttach IStream STREAM_SEEK_SET

Keywords: kbprb KB820721

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.