Click here to Skip to main content
12,560,367 members (43,720 online)
Click here to Skip to main content
Add your own
alternative version


32 bookmarked

Getting Dll Module Handle in ATL 7.0 projects

, 7 Mar 2002
Rate this:
Please Sign up or sign in to vote.
Simplest way to retrieve HINSTANCE of your ATL Object
<!-- Add the rest of your HTML here -->


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


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


About the Author

United States United States
Whatever !

You may also be interested in...


Comments and Discussions

GeneralThanks ! Pin
pg--az13-May-05 20:13
memberpg--az13-May-05 20:13 
Generalother way.... Pin
=Hermitry=1-May-03 8:51
member=Hermitry=1-May-03 8:51 
GeneralCComModule... Pin
Tim Smith7-Mar-02 15:22
memberTim Smith7-Mar-02 15:22 
GeneralRe: CComModule... Pin
Unsigned Char7-Mar-02 19:26
memberUnsigned Char7-Mar-02 19:26 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Terms of Use | Mobile
Web01 | 2.8.161026.1 | Last Updated 8 Mar 2002
Article Copyright 2002 by Deleted
Everything else Copyright © CodeProject, 1999-2016
Layout: fixed | fluid