LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
Ai Ai is offline
external usenet poster
 
Posts: 2
Default BSTR to char* Help!

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?
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Char(10) or Char(13) in body of email ryguy7272 Excel Programming 2 November 12th 08 08:56 PM
FIND 1 char in cell of any 3 char =True Nastech Excel Discussion (Misc queries) 5 April 26th 08 02:17 PM
8500 cells with phone number(7 char.), wishing to add area code (10 char.) [email protected] Excel Discussion (Misc queries) 6 March 10th 06 05:13 PM
Getting rid of char(160) Biff Excel Programming 2 March 10th 06 01:20 AM
How to removed the first three char and last char in XLS Lillian Excel Programming 1 December 21st 04 12:34 AM


All times are GMT +1. The time now is 02:07 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"