|
-
May 27th, 2013, 07:41 AM
#7
Re: COleVariant in WinAPI (afxdisp.h)
 Originally Posted by VictorN
Try to change your code to be:
Code:
VARIANT xx;
xx.vt=VT_BSTR;
xx.pcVal= L"a1";
this doesn't create a proper VARIANT to a BSTR, even if you fixed it to set it to bstrVal instead of pcVal.
it creates a variant of type VT_BSTR with the BSTR part pointing to a static wide character string. Wide char string != BSTR.
Depending on how the receiving function works. This can either work without any form of issue, or it can have all kinds of failures.
BSTR's are BSTR's, they are NOT simply pointers to any type of wide character strings.
The above would be correct if you used a VT_LPWSTR type, but not everything accepting a VARIANT will handle that type properly (a lot don't).
If you pass a VT_BSTR, make sure you have an actual BSTR, meaning, it should be allocated via SysAllocString() or it should be NULL indicating an empty string (not a NULL string). There are C++ wrapper classes such as CComBSTR (ATL/MFC) and _bstr_t (compiler COM support) to help you manage BSTR's.
Last edited by OReubens; May 27th, 2013 at 07:44 AM.
Tags for this Thread
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
|