Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles
(untagged)

Getting Dll Module Handle in ATL 7.0 projects

0.00/5 (No votes)
7 Mar 2002 1  
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 !!!

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here