65.9K
CodeProject is changing. Read more.
Home

Getting Dll Module Handle in ATL 7.0 projects

starIconstarIconstarIconstarIcon
emptyStarIcon
starIcon

4.78/5 (7 votes)

Mar 7, 2002

viewsIcon

80471

Simplest way to retrieve HINSTANCE of your ATL Object

Introduction

In ATL 7.0 the module statement in your main source file, automatically implements DllMain, DllRegisterServer and DllUnregisterServer for you.

The old fashioned way (not so old though) has been thrown away and _Module is not part of the implementation anymore.

Obviously Microsoft isn't much talking about it anyway, but this object was containing some handy properties that could be very useful in order to manipulate elements that are part of the DLL such as resources.

One way is to use the old GetModuleHandle() API function but in some cases it wouldn't work for you (and me as well).

So to get access to what was _Module in ATL 3.0 you simply use _AtlBaseModule.

AtlBaseModule has now succeeded to the old CComModule, pretty cool since there is no real mention of its data members in the documentation.

However instead of using directly m_hInst you could access it through methods such as GetModuleInstance(), GetResourceInstance() and GetHInstanceAt() for resource localization and internationalization  (thanx to Tim). Anyway, I hope it will solve your problem, like it has solved mine.

Really small example

HINSTANCE hInst = (HINSTANCE) _AtlBaseModule.m_hInst;
HICON hIcon = LoadIcon(hInst, MAKEINTRESOURCE(212));
Enjoy !!!