Codestone Ltd logo

Search FAQ


Internet Mail Client Control FAQs/Objects/Message Object

How can I access the data in the BodyBinary property from VC++?

ID: S4E28 DATE: 06/01/2003

Assuming that you are using the #import directive to create wrapper classes for the objects in the library you will probably have some code which looks like this:

VARIANT vData;
VariantInit(&vData);
hr pSection->get_BodyBinary(&vData);

So how do you access the binary data and work out how large it is?

On return from pSection->get_BodyBinary(&vData) vData.vt is VT_ARRAY|VT_UI1 and vData.parray is a pointer to a SAFEARRAY of unsigned chars.

You can either use the SAFEARRAY API calls to access the data:

_ASSERTE(vData.vt==VT_ARRAY|VT_UI1 && vData.pArray!=NULL);
SAFEARRAY *pSA=vData.pArray;

long lUBound;
long lLBound;
long lSize;
unsigned char *pbData;

SafeArrayGetUBound(pSA,1,&lUBound);
SafeArrayGetLBound(pSA,1,&lLBound);
lSize=lUBound-lLBound+1;

SafeArrayAccessData(pSA,(void **)&pbData);

// Do something with the data here ...

SafeArrayUnaccessData(pSA);// NB pbData may not be valid after this call

or you can live dangerously:

_ASSERTE(vData.vt==VT_ARRAY|VT_UI1 && vData.pArray!=NULL);

SAFEARRAY *pSA=vData.pArray;

long lSize=pSA->rgsabound[0].cElements;
unsigned char *pbData=(unsigned char *)pSA->pvData;

// pbData may not be valid for long, copy the data
// somewhere safe!

Related questions


Can't find the answer to your question? We're here to help!