18.04.2015 Views

ArcGIS Engine Developer Guide

ArcGIS Engine Developer Guide

ArcGIS Engine Developer Guide

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

VISUAL C++<br />

delete[] pvars; // Clean up the parameter list.<br />

}<br />

VOID Fire_OnMouseUp(LONG button, LONG shift, LONG x, LONG y)<br />

{<br />

// ... Other events<br />

To fire an event from the source, call Fire_OnMouseDown when required.<br />

A similar approach can be used for firing events to a pure COM (non-IDispatch)<br />

interface. The wizard will not generate the connection point class, so this must be<br />

written by hand; the following example illustrates a class that will fire an<br />

ITOCBuddyEvents::ActiveViewReplaced event; ITOCBuddyEvents is a pure COM,<br />

non-IDispatch interface. The key difference is that there is no need to package<br />

the parameters; a direct method call can be made.<br />

template < class T ><br />

class CProxyTOCBuddyEvents : public IConnectionPointImpl< T,<br />

&IID_ITOCBuddyEvents, CComDynamicUnkArray ><br />

{<br />

// This class based on the ATL-generated connection point class<br />

public:<br />

void Fire_ActiveViewReplaced(IActiveView* pNewActiveView)<br />

{<br />

T* pT = static_cast< T* >(this);<br />

int nConnectionIndex;<br />

int nConnections = this->m_vec.GetSize();<br />

for (nConnectionIndex = 0; nConnectionIndex < nConnections;<br />

nConnectionIndex++)<br />

{<br />

pT->Lock();<br />

CComPtr< IUnknown > sp=this->m_vec.GetAt(nConnectionIndex);<br />

pT->Unlock();<br />

ITOCBuddyEvents* pTOCBuddyEvents = reinterpret_cast< ITOCBuddyEvents*<br />

>(sp.p);<br />

if (pTOCBuddyEvents)<br />

pTOCBuddyEvents->ActiveViewReplaced(pNewActiveView);<br />

}<br />

}<br />

};<br />

IDL declarations for an object that supports events<br />

When an object is exported to a type library, the event interfaces are declared by<br />

using the [source] tag against the interface name. For example, an object that fires<br />

ITOCBuddyEvents declares:<br />

[source] interface ITOCBuddyEvents;<br />

If the outbound interface is a dispatch events interface, dispinterface is used instead<br />

of interface. In addition, a coclass can have a default outbound interface;<br />

this is specified with the [default] tag. Default interfaces are identified by some<br />

design environments (for example, Visual Basic 6). Following is the declaration<br />

for the default outbound events interface:<br />

[default, source] dispinterface IMyEvents2;<br />

138 • <strong>ArcGIS</strong> <strong>Engine</strong> <strong>Developer</strong> <strong>Guide</strong>

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!