Click to See Complete Forum and Search --> : [COM] How to get BSTR from COM


reverse
April 19th, 1999, 06:45 AM
I want to receive string from COM component.

<IDL>
HRESULT Test([out, string] BSTR* abc);

<Test Server>
HRESULT Test(/*out, string*/ BSTR* abc)
{
_bstr_t bstrResult(abc, false);
bstrResult = L"This is a test";
abc = (BSTR)bstrResult;
return S_OK;
}

<Test Client : VB>
Dim obj as new WebCom
Dim s as String

obj.Test s

---------------

But, this code occurs error (in MTS).
How COM server pass BSTR string to client?


A programmer who loves Goethe.

mihai
April 19th, 1999, 07:06 AM
See SysAllocString, SysFreeString, OLE2T, T2OLE, USES_CONVERSION
Sincerely, Mihai

Bob Place
April 19th, 1999, 08:01 AM
Since _bstr_t performs all of your allocation for you I believe you can do something like this:

HRESULT Test(/*out, string*/ BSTR* abc)
{
_bstr_t bstrResult;
bstrResult = L"This is a test";
abc = bstrResult.copy();
return S_OK;
}

Magnus
April 19th, 1999, 08:26 AM
try s = obj.Test

MoMoPi
April 21st, 1999, 02:49 PM
_bstr_t bstrResult(abc, false);
bstrResult = L"This is a test"; // Wrong

Try to do this.

wchar_t wbst[]= L"This is a test";
abc = SysAllocString(wbst);


I hope this will help you.