I need to create a "SAFEARRAY of bytes" from a "BSTR" to pass it to a function.
i have tried following ways to create a BYTE* from BSTR.
Is there any other ways to convert a BSTR to BYTE* which won't lead to lose any data?
BSTR bstr = SysAllocString(L"This is a basic string which encoded in UTF-16!!ɏ");
int len = WideCharToMultiByte(CP_UTF8, 0, bstr, -1, NULL, 0, NULL, NULL);
BYTE *pByte = new BYTE[len];
if (len > 0)
{
/*
for(int i=0; i<len; i++)
{
pByte[i] = (BYTE) bstr[i]; //using this way may lead to lose data.
}
*/
WideCharToMultiByte(CP_UTF8, 0, bstr, -1, (LPSTR)&pByte[0], len, NULL, NULL);
//cout << "Byte Array: " << pByte << endl;
}
delete []pByte;