Click here to Skip to main content
15,886,063 members
Articles / Desktop Programming / ATL
Article

Getting Dll Module Handle in ATL 7.0 projects

Rate me:
Please Sign up or sign in to vote.
4.78/5 (7 votes)
7 Mar 2002 79.9K   32   4
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;<BR>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


Written By
United States United States
Whatever !

Comments and Discussions

 
GeneralThanks ! Pin
pg--az13-May-05 20:13
pg--az13-May-05 20:13 
Generalother way.... Pin
=Hermitry=1-May-03 8:51
=Hermitry=1-May-03 8:51 
GeneralCComModule... Pin
Tim Smith7-Mar-02 15:22
Tim Smith7-Mar-02 15:22 
GeneralRe: CComModule... Pin
Deleted7-Mar-02 19:26
Deleted7-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.