COleDispatchDriver::AttachDispatch
voidAttachDispatch(LPDISPATCHlpDispatch**,BOOLbAutoRelease=TRUE);**
Parameters
lpDispatch
Pointer to an OLE IDispatch object to be attached to the COleDispatchDriver object.
bAutoRelease
Specifies whether the dispatch is to be released when this object goes out of scope.
Remarks
Call the AttachDispatch member function to attach an pointer to the COleDispatchDriver object. This function releases any IDispatch pointer that is already attached to the COleDispatchDriver object.
Example
// VC++ Client for the VJ++ ComCallingJava sample
// (33B0ECE2-E706-11CF-A0C2-00AA00A71DD8)
static const CLSID GCDclsid =
{ 0x33B0ECE2, 0xE706, 0x11CF, { 0xa0, 0xC2, 0x0, 0xaa, 0x0,
0xa7, 0x1d, 0xd8 }};
// (33B0ECE1-E706-11cf-A0C2-00AA00A71DD8)
static const CLSID IGCDclsid =
{ 0x33B0ECE1, 0xE706, 0x11CF, { 0xa0, 0xC2, 0x0, 0xaa, 0x0,
0xa7, 0x1d, 0xd8 }};
void CComjavaView::OnLButtonDown(UINT nFlags, CPoint point)
{
CString str;
LPDISPATCH pDisp;
IGCD VJCom; // ClassWizard generated COleDispatchDriver
// derived class created from the Euclid typelibrary.
VJCom.CreateDispatch(GCDclsid);
pDisp = VJCom.m_lpDispatch;
HRESULT hr = pDisp->QueryInterface( IGCDclsid,
(void**)&VJCom.m_lpDispatch);
if (hr == S_OK)
pDisp->Release();
else
VJCom.AttachDispatch(pDisp, TRUE);
// Call the ClassWizard generated helper function GCD. This
// function will in turn call COleDispatchDriver::InvokeHelper.
str.Format("The least common denominator of 40 and 24 is %d",
VJCom.GCD(40,24));
AfxMessageBox(str);
VJCom.ReleaseDispatch();
CView::OnLButtonDown(nFlags, point);
}
COleDispatchDriver Overview | Class Members | Hierarchy Chart
See Also COleDispatchDriver::DetachDispatch, COleDispatchDriver::ReleaseDispatch, COleDispatchDriver::CreateDispatch, COleDispatchDriver::m_lpDispatch, COleDispatchDriver::m_bAutoRelease