|
-
June 1st, 1999, 11:46 AM
#1
How to deal with binary data?
I need to build a control which has a function that returns a binary data array. The function will be called in VB. What data type should I use in VC++?
Note, the binary data array size is dynamic. If I dynamically allocates memory, where should I delete the memory?
Any smaple codes are greatly appreciated.
Thanks.
-
June 1st, 1999, 12:44 PM
#2
Re: How to deal with binary data?
I use a variant safearray when I need to pass an array of bytes.
// initialize variant
VARIANT vData;
VariantInit(&vData);
// create safearray
SAFEARRAY* psa = NULL;
SAFEARRAYBOUND rgsabound;
rgsabound.lLbound = 0;
rgsabound.cElements = lNumBytes;
psa = SafeArrayCreate(VT_UI1, 1, &rgsabound);
// access safearray
BYTE HUGEP* pArrayData;
SafeArrayAccessData(psa, (void HUGEP**) &pArrayData);
// fill array
memcpy(pArrayData, pData, lNumBytes);
// release
SafeArrayUnaccessData(psa);
// return
vData.vt = VT_UI1 | VT_ARRAY;
vData.parray = psa;
The caller (VB) is responsible to release memory allocated.
-
June 1st, 1999, 01:11 PM
#3
Re: How to deal with binary data?
Thank you.
I still have a question.
Should the function prototype be:
STDMETHOD(Flush)(/*[out, retval]*/ VARIANT* buf);
or
STDMETHOD(Flush)(/*[out, retval]*/ SAFEARRAY* buf); ?
Can you recommend a good book on this?
Thanks.
-
June 1st, 1999, 01:35 PM
#4
Re: How to deal with binary data?
Use the VARIANT* parameter type.
I have found the following books very helpful.
Beginning ATL COM Programming by Dr. Richard Grimes and others from Wrox Press
Professional ATL COM Programming by Dr. Richard Grimes from Wrox Press
Essential COM by Don Box from The Addison-Wesley Object Technology Series
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|