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

removal would result in a serious corruption of the registry. InprocServer32 is the<br />

standard COM mechanism that relates a component GUID to a DLL file; ATL<br />

will insert the correct module name using the %MODULE% variable. Other<br />

entries under the GUID specify the ProgID, threading model, and type library to<br />

use with this component.<br />

If the GUID of a component is changed during<br />

development or the type library name is<br />

changed, then it is important to keep the .rgs<br />

content consistent with these changes. Otherwise,<br />

the registry will be incorrect and object<br />

creation can fail.<br />

To register a COM coclass into a component category, there are two approaches.<br />

The recommended approach is illustrated above: place GUIDs for component<br />

categories beneath an Implemented Categories key, which in turn is under the<br />

GUID of the coclass. The second approach is to use ATL macros in an objects<br />

header file: BEGIN_CATEGORY_MAP, IMPLEMENTED_CATEGORY, or<br />

END_CATEGORY_MAP. However, these macros do not correctly remove<br />

registry entries as explained in the Microsoft <strong>Developer</strong> Network (MSDN) article<br />

Q279459 BUG: ‘Component Category Registry Entries Not Removed in ATL<br />

Component’. A header file is supplied with the GUIDs of all the component<br />

categories used by <strong>ArcGIS</strong>; this is available in \Program<br />

Files\<strong>ArcGIS</strong>\include\CatIDs\ArcCATIDs.h.<br />

Debugging ATL code<br />

In addition to the standard Visual Studio facilities, ATL provides a number of<br />

debugging options with specific support for debugging COM objects. The output<br />

of these debugging options is displayed in the Visual C++ Output window. The<br />

QueryInterface call can be debugged by setting the symbol _ATL_DEBUG_QI,<br />

AddRef, and Release calls with the symbol _ATL_DEBUG_INTERFACES, and<br />

leaked objects can be traced by monitoring the list of leaked interfaces at termination<br />

time when the _ATL_DEBUG_INTERFACES symbol is defined. The<br />

leaked interfaces list has entries like the following:<br />

INTERFACE LEAK: RefCount = 1, MaxRefCount = 3, {Allocation = 10}<br />

On its own, this does not tell you much apart from the fact that one of your<br />

objects is leaking because an interface pointer has not been released. However,<br />

the Allocation number allows you to automatically break when that interface is<br />

obtained by setting the m_nIndexBreakAt member of the CComModule at server<br />

startup. This in turn calls the function DebugBreak to force the execution of the<br />

code to stop at the relevant place in the debugger. For this to work, the program<br />

flow must be the same.<br />

extern "C"<br />

BOOL WINAPI DllMain(HINSTANCE hInstance, DWORD dwReason, LPVOID /<br />

*lpReserved*/)<br />

{<br />

if (dwReason == DLL_PROCESS_ATTACH)<br />

{<br />

_Module.Init(ObjectMap, hInstance, &LIBID_HISTORYLib);<br />

DisableThreadLibraryCalls(hInstance);<br />

_Module.m_nIndexBreakAt = 10;<br />

}<br />

else if (dwReason == DLL_PROCESS_DETACH)<br />

{<br />

_Module.Term();<br />

}<br />

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