Link to home
Start Free TrialLog in
Avatar of zemanek
zemanek

asked on

COM: BSTR in structure. How pass it?

Hi,
I have this problem:
I want to pass some structure with two BSTR strings from server to client.

SERVER SIDE:
============
part of my IDL:
---------------
typedef struct
{
      BSTR      text1;
      BSTR      text2;
} NWVaTestStruct;

....

interface INWVaTest : IUnknown
{
      [helpstring("method GetTestData")] HRESULT GetTestData([out] NWVaTestStruct** ppData);
      ....
};

....

part of H file of CNWVaTest class:
----------------------------------
STDMETHOD(GetTestData)(/*[out]*/ NWVaTestStruct** ppData);

part of CPP file of CNWVaTest class:
------------------------------------
STDMETHODIMP CNWVaTest::GetTestData(/*[out]*/ NWVaTestStruct** ppData)
{
      *ppData = new NWVaTestStruct;

      (*ppData)->text1 = (BSTR)CComBSTR("aaa");
      (*ppData)->text2 = (BSTR)CComBSTR("bbb");

      return S_OK;
}

CLIENT SIDE:
============
NWVaTestStruct* testData;

m_pVaTest->GetTestData(&testData);

CString sTemp1,sTemp2;
BSTR bstr;

sTemp1 = CString(testData->text1);
sTemp2 = CString(testData->text2);
----------------------------------------

Both strings, sTemp1 and sTemp2, contains "bbb". What's wrong?
How can I pass structure with BSTRs?

Thank you.
ASKER CERTIFIED SOLUTION
Avatar of xyu
xyu

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial