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 />

The following issues with events are documented<br />

on the MSDN Knowledge Base when using<br />

IDispEventImpl. Fixes to ATL code are shown in<br />

MSDN for these issues; however, it is not always<br />

desirable to modify or copy ATL header files. In<br />

this case, IDispEventSimpleImpl can be used<br />

instead.<br />

BUG: Events Fail in ATL Containers when Enum<br />

Used as Event Parameter (Q237771)<br />

BUG: IDispEventImpl Event Handlers May Give<br />

Strange Values for Parameters (Q241810)<br />

BEGIN_SINK_MAP(CMyDialog)<br />

// Make sure the Event Handlers have __stdcall calling convention.<br />

// The 0x1 is the Dispatch ID of the OnMouseDown method.<br />

SINK_ENTRY(IDC_MAPCONTROL1, 0x1, OnMouseDownMapcontrol1)<br />

END_SINK_MAP()<br />

};<br />

Using IDispEventSimpleImpl to listen to events<br />

As the name of this template suggests, it is a simpler version of IDispEventImpl.<br />

The type library is no longer used to turn the IDispatch arguments into a C++<br />

method call. While this may be a simpler implementation, it now requires the<br />

developer to supply a pointer to a structure describing the format of the event<br />

parameters. This structure is typically placed in the .cpp file. For example, here is<br />

the structure describing the parameters of an OnMouseDown event for the<br />

MapControl:<br />

_ATL_FUNC_INFO g_ParamInfo_MapControl_OnMouseDown =<br />

{<br />

CC_STDCALL,<br />

// Calling convention<br />

VT_EMPTY,<br />

// Return type<br />

6, // Number of arguments<br />

{VT_I4, VT_I4, VT_I4, VT_I4, VT_R8, VT_R8} // VariantArgument types<br />

};<br />

The header file now inherits from IDispEventSimpleImpl and uses a different<br />

macro, SINK_ENTRY_INFO, in the SINK_MAP. Also, the events interface ID is<br />

required; #import can be used to define this symbol. Note that a dispatch interface<br />

is normally prefixed with DIID instead of IID.<br />

#pragma once<br />

See the ‘Importing <strong>ArcGIS</strong> type libraries’ section<br />

earlier in this chapter for an explanation of<br />

#import.<br />

#include "resource.h" // Main symbols<br />

#include <br />

// Reference to structure defining event parameters<br />

extern _ATL_FUNC_INFO g_ParamInfo_MapControl_OnMouseDown;<br />

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

// CMyDialog2<br />

class CMyDialog2 :<br />

public CAxDialogImpl,<br />

public IDispEventSimpleImpl<br />

{<br />

public:<br />

// Message handler code removed, it is the same as CMyDialog using<br />

IDispEventSimple<br />

BEGIN_SINK_MAP(CMyDialog2)<br />

// Make sure the Event Handlers have __stdcall calling convention.<br />

// The 0x1 is the Dispatch ID of the OnMouseDown method.<br />

SINK_ENTRY_INFO(IDC_MAPCONTROL1, // ID of event source<br />

132 • <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!