PDA

View Full Version : C++ API BSTR* out parameters



pwilson101
12-02-2004, 11:20 AM
Hi

I have a C++ API (not COM) with a method that has a BSTR* out parameter:
HRESULT __stdcall GetSomeResults(BSTR pathName, BSTR* results);

Does any know how I get the 'results' value back into my InstallScript?

I've tried a variety of declarations of the call and other tricks from this community, eg SPrintf, and the like but nothing seems to get the string back correctly.

Please help!

Paul

Christopher Painter
12-03-2004, 10:55 PM
I'm not the biggest C++ geek in the world so this may not help. From what I've read on MSDN BSTR and unicode string arrays that can contain nulls and keep going.

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/automat/htm/chap7_5alv.asp

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vccore/html/vcconstringsallocatingreleasingmemoryforbstr.asp

From the second link it sounds like you need to create a pointer. Somehow the API allocates the memory for the pointer and you are only responsible for freeing it. Once you have the BSTR you have to use a variety of APIs to convert it to more useful datatypes.

Hope I'm close to correct there. I've never done BSTR's.

This looks helpful also:

http://blogs.gotdotnet.com/ericli/permalink.aspx/853ae05f-7610-4531-ab1b-070695e61168