Knowledge Base Nr: 00063 BSTR_sample.cpp - http://www.swe-kaiser.de

MFC: Dieses Beispiel demonstriert den Gebrauch von BSTRs in C++ (VC++ 5.0)
Der Server nutzt ATL mit MFC Support und der Client nur die MFC

  
/*client implementation:*/

CString strCommand = "";
BSTR bstrCommand = strCommand.AllocSysString();

BSTR bstrResult;

HRESULT hr = m_pBCBinterface->CmdInterface(bstrCommand, &bstrResult);

CString strItem = bstrResult;
::SysFreeString(bstrResult);


/*server implementation:*/

/*idl:*/
[helpstring("method CmdInterface")] HRESULT CmdInterface([in] BSTR bstrCommand, [out] BSTR* bstrItem);

/*cpp:*/
CString strCommand = bstrCommand;
::SysFreeString(bstrCommand);

CString strItem = "<not filled>";
*bstrResult = strItem.AllocSysString();