A
Ai
Hi all,
I'm trying to convert a BSTR string pass from VBA to a xll/dll but
without success. I tried the following:
1. WideCharToMultiByte (result is ????, if I replace the bstr with a
hardcoded string say with *bstr = SysAllocString(L"this is BSTR!!!"),
it'll work)
DWORD len, bstrLength;
bstrLength = SysStringLen(*bstr);
len = WideCharToMultiByte(CP_ACP, 0, *bstr, bstrLength, 0, 0, 0, 0);
size_t result;
if(len > 0)
{
result = WideCharToMultiByte(CP_ACP, 0, *bstr, bstrLength, buffer,
len, 0, 0);
buffer[len] = 0;//null-terminated char
}
2. wcstombs (result is empty string)
int len = wcslen(*bstr);
char *dest = (char*)malloc(len);
size_t result = wcstombs(dest, (wchar_t*)bstr, len);
3. Direct casting work but it'll crash the program later
strcat(buffer, (char*)(*bstr));
Anyone have any advise?
I'm trying to convert a BSTR string pass from VBA to a xll/dll but
without success. I tried the following:
1. WideCharToMultiByte (result is ????, if I replace the bstr with a
hardcoded string say with *bstr = SysAllocString(L"this is BSTR!!!"),
it'll work)
DWORD len, bstrLength;
bstrLength = SysStringLen(*bstr);
len = WideCharToMultiByte(CP_ACP, 0, *bstr, bstrLength, 0, 0, 0, 0);
size_t result;
if(len > 0)
{
result = WideCharToMultiByte(CP_ACP, 0, *bstr, bstrLength, buffer,
len, 0, 0);
buffer[len] = 0;//null-terminated char
}
2. wcstombs (result is empty string)
int len = wcslen(*bstr);
char *dest = (char*)malloc(len);
size_t result = wcstombs(dest, (wchar_t*)bstr, len);
3. Direct casting work but it'll crash the program later
strcat(buffer, (char*)(*bstr));
Anyone have any advise?