WideChar to Variant conversion
-
Can anyone tell how to convert a widechar string to VARIANT I have an unsigned char* string , I am converting it to widechar using MultiByteToWideChar. How to convert it to VARIANT ? The data is getting lost if i use ColeVariant.
If you paste your code here, that would be more helpful but simply u can do it by setting the vt of variant to VT_BSTR and then create a bstr. Put the string in BSTR by using ::SysAllocString and set that BSTR in the variant. Something like: BSTR bstrString = ::SysAllocString(str); VARIANT var; var.vt = VT_BSTR; var.bstrval = bstrString; Regards,
"Some people believe football is a matter of life and death. I'm very disappointed with that attitude. I can assure you it is much, much more important than that. -- Bill Shankly"
-
If you paste your code here, that would be more helpful but simply u can do it by setting the vt of variant to VT_BSTR and then create a bstr. Put the string in BSTR by using ::SysAllocString and set that BSTR in the variant. Something like: BSTR bstrString = ::SysAllocString(str); VARIANT var; var.vt = VT_BSTR; var.bstrval = bstrString; Regards,
"Some people believe football is a matter of life and death. I'm very disappointed with that attitude. I can assure you it is much, much more important than that. -- Bill Shankly"
I have sumthng like this VARIANT getData() { unsigned char* puc_Data = " SOME TEXT "; // I am converting the above unsigned char to whar_t* using MultiByteToWideChar(CP_UTF8,..,puc_Data,len,wchar_t*,len); // I want to take this wchar string and convert it to VARIANT // Doing it thru COleVariant ColeVariant var(wchar string ); // Data is getting lost sumwhere here ... return var; Can anyone suggest wat i m doing wrong??
-
I have sumthng like this VARIANT getData() { unsigned char* puc_Data = " SOME TEXT "; // I am converting the above unsigned char to whar_t* using MultiByteToWideChar(CP_UTF8,..,puc_Data,len,wchar_t*,len); // I want to take this wchar string and convert it to VARIANT // Doing it thru COleVariant ColeVariant var(wchar string ); // Data is getting lost sumwhere here ... return var; Can anyone suggest wat i m doing wrong??
Why not just do this and let COleVariant do what it is designed to do?
ColeVariant getData()
{
char* puc_Data = " SOME TEXT ";
ColeVariant var(puc_Data);
return var;
}