18.04.2015 Views

ArcGIS Engine Developer Guide

ArcGIS Engine Developer Guide

ArcGIS Engine Developer Guide

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

VISUAL C++<br />

DIID_IMapControlEvents2, // Interface to listen to<br />

0x1, // Dispatch ID of MouseDown<br />

OnMapControlMouseDown, // Method to call when event arrives<br />

&g_ParamInfo_MapControl_OnMouseDown) // Parameter info for method call<br />

END_SINK_MAP()<br />

};<br />

Listening to more than one IDispatch event interface on a COM<br />

object<br />

If a single COM object needs to receive events from more than one IDispatch<br />

source, then this can cause compiler issues with ambiguous definitions of the<br />

DispEventAdvise method. This is not normally a problem in a dialog box, as<br />

AtlAdviseSinkMap will handle all the connections. The ambiguity can be avoided<br />

by introducing different typedefs each time IDispEventSimpleImpl is inherited. The<br />

following example illustrates a COM object called CListen, which is a sink for<br />

dispatch events from a MapControl and a PageLayoutControl.<br />

#pragma once<br />

#include "resource.h"<br />

// Main symbols<br />

// This is the parameter information.<br />

extern _ATL_FUNC_INFO g_ParamInfo_MapControl_OnMouseDown;<br />

extern _ATL_FUNC_INFO g_ParamInfo_PageLayoutControl_OnMouseDown;<br />

//<br />

// Define some typedefs of the dispatch template.<br />

//<br />

class CListen; // Forward definition<br />

typedef IDispEventSimpleImpl<br />

IDispEventSimpleImpl_MapControl;<br />

typedef IDispEventSimpleImpl<br />

IDispEventSimpleImpl_PageLayoutControl;<br />

////////////////////////////////////////////////////////////////////////////<br />

// CListen<br />

class ATL_NO_VTABLE CListen :<br />

public CComObjectRootEx,<br />

public CComCoClass,<br />

public IDispEventSimpleImpl_MapControl,<br />

public IDispEventSimpleImpl_PageLayoutControl,<br />

public IListen<br />

{<br />

public:<br />

CListen()<br />

Chapter 4 • <strong>Developer</strong> environments • 133

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

Saved successfully!

Ooh no, something went wrong!