OLE Automation controller example w/BSTRs
Joe Vannucci -- vannuccj@ix.netcom.com Friday, February 14, 1997 Environment: VC 1.52c -> VC 4.2b Win 95 I'm looking for a good sample of an OLE automation controller that calls server methods with BSTRs as params and return values. The examples I've found in the usual places are too simplistic (no BSTRs). I'm not clear on the "clean up" of BSTRs from the controller side -- especially since they can come back as CStrings. Also not clear on how to pass a CString as a param to an object method receiving a BSTR. Also what are the conversion macros I should use to convert between BSTR and const char*? I'm subclassing COleDispatchDriver. Thanks in advance! -joe vannucci vannuccj@ix.netcom.com
Deirdre Collins -- deirdre@technicon.com Sunday, February 16, 1997 Here's a brief sample : Client side : long ccqId; CString fileName = file_dlg.GetPathName (); BSTR bstrFileName = fileName.AllocSysString (); hr = m_pIStorageCCQData->Open (NULL, (LPCTSTR)fileName, &m_pIStorage); if (hr == S_OK) { hr = m_pIStorageCCQData->GetOutputReference (m_pIStorage, &ccqId, &bstrFileName); fileName = bstrFileName; } SysFreeString (bstrFileName); Server side: STDMETHODIMP IOObj::XStorageCCQData:: GetOutputReference (IStorage* pIStorage, long* pCCQId, BSTR* pCCQFileName) { METHOD_PROLOGUE(IOObj, StorageCCQData) HRESULT hr = S_OK; CListEntry * entry = m_saveList.Find (pIStorage); if (entry) { if (entry->m_recordId != NO_KEY) { if (pCCQId) { *pCCQId = entry->m_recordId; } else { hr = ITF_E_INVALIDPARAMETER; } } else if (!entry->m_document.IsEmpty ()) { if (pCCQFileName) { BSTR bstr = entry->m_document.AllocSysString (); SysFreeString (*pCCQFileName); *pCCQFileName = bstr; } else { hr = ITF_E_INVALIDPARAMETER; } } } else { hr = ITF_E_STORAGEUNKNOWN; } return (hr); } >-----Original Message----- >From: Joe Vannucci [SMTP:vannuccj@ix.netcom.com] >Sent: Saturday, February 15, 1997 3:04 AM >To: mfc-l@netcom.com >Subject: OLE Automation controller example w/BSTRs > >Environment: VC 1.52c -> VC 4.2b Win 95 > >I'm looking for a good sample of an OLE automation controller that calls >server methods with BSTRs as params and return values. The examples >I've found in the usual places are too simplistic (no BSTRs). I'm not >clear on the "clean up" of BSTRs from the controller side -- especially >since they can come back as CStrings. Also not clear on how to pass a >CString as a param to an object method receiving a BSTR. Also what are >the conversion macros I should use to convert between BSTR and const >char*? > >I'm subclassing COleDispatchDriver. > >Thanks in advance! >-joe vannucci >vannuccj@ix.netcom.com
David Lowndes -- David.Lowndes@bj.co.uk Monday, February 17, 1997 >I'm looking for a good sample of an OLE automation controller that calls server methods with BSTRs as params and return values. The examples I've found in the usual places are too simplistic (no BSTRs). I'm not clear on the "clean up" of BSTRs from the controller side -- especially since they can come back as CStrings. Also not clear on how to pass a CString as a param to an object method receiving a BSTR. Also what are the conversion macros I should use to convert between BSTR and const char*? < Joe, There's a series of articles on the ms web site, one of which is "Article 3. Strings the OLE Way" that details using BSTRs in detail. Have a look at www.microsoft.com/oledev/olecom/article3.htm. Dave
Become an MFC-L member | Вернуться в корень Архива |