FYI I am begginer in COM\ATL and unicode
I am using SafeArrayPutElement(safearray*,LONG,void*)
in my code and the problem is...
here, the function works fine when i give the third parameter as L"ItWorks"
i.e
SafeArrayPutElement(safearray*,LONG, L"ItWorks");
but if i use
wchar_t str;
str = 'a';
SafeArrayPutElement(safearray*,LONG,&str);
this function fails saying E_OUTOFMEMORY
here my need is, i have a string in char*
variable, some how i need to use this as the THIRD parameter for the above function.
Can anyone please help me in this regard.
TIA
Naveen
The only string type that is safe to use in COM in a
BSTR
, not a rawwchar_t*
. This is because aBSTR
contains extra internal data that COM uses for marshalling purposes. UseSysAllocString()
orSysAllocStringLen()
to allocate a newBSTR
from awchar_t*
, and then useSysFreeString()
to free it when you are finished using it, eg:.