LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #4   Report Post  
Posted to microsoft.public.excel.programming,microsoft.public.excel.sdk
external usenet poster
 
Posts: 8
Default Passing a string to excel from a C app

The working C++ code sample I'm copying from passes strings as VT_BSTR,
and it uses the SysAllocString method of CString to convert the C
strings into BSTR's for passing. Unfortunately, I can't seem to find a
C equivalent of CString::SysAllocString().

BSTR b;
b = SysAllocString(lpsz);
parm1.vt = VT_BSTR;
parm1.bstrVal = b;


Got it to work. Turns out SysAllocString does work from C. It's just
that it needs a multi-byte char string as input (I guess the C++ version
has a variant that take and converts a regular char string. So in C,
the conversion has to happen in 2 phases. This code works:

BSTR b;
LPCWSTR ws;
int len;

len = strlen(szStr) + 1;
ws = (LPCWSTR) malloc(len*2);
MultiByteToWideChar(CP_ACP, 0, szStr, len, ws, len*2);
b = SysAllocString(ws);
parm1.vt = VT_BSTR;
parm1.bstrVal = b;
free(ws);

 
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
Passing Query String into MS Excel napval Excel Programming 0 June 20th 07 10:19 PM
Passing Query String into MS Excel napval Excel Discussion (Misc queries) 0 June 19th 07 06:04 AM
Passing a String in Array to Range as String [email protected] Excel Programming 2 September 1st 04 01:13 AM
string passing to DLL Christoph Wirz Excel Programming 1 February 20th 04 02:40 PM
PASSING A STRING VALUE Sirron Excel Programming 2 August 26th 03 06:40 PM


All times are GMT +1. The time now is 02:50 PM.

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"