views:

594

answers:

3

I have created a DLL in VC++ as Win32 project

DLLMAIN function is

BOOL APIENTRY DllMain( HMODULE hModule,
                       DWORD  ul_reason_for_call,
                       LPVOID lpReserved
                     )
{
    return TRUE;
}

Now I need HINSTANCE of the DLL , that need to be passed to Win32 functions.

Are HMODULE and HINSTANCE same?

How can I get HINSTANCE?

+1  A: 

I think that these are the same. If you want HINSTANCE of the running process (exe), you should use

GetModuleHandle(NULL);
Yossarian
+4  A: 

An excerpt from the book Windows Via C/C++ [1]

Note As it turns out, HMODULEs and HINSTANCEs are exactly the same thing. If the documentation for a function indicates that an HMODULE is required, you can pass an HINSTANCE and vice versa. There are two data types because in 16-bit Windows HMODULEs and HINSTANCEs identified different things

[1] Richter, Jeffery and Nasarre, Christophe, Windows Via C/C++, 5th ed, Redmond: Microsoft Press 2008, pp. 74

Swiss
More info here: http://blogs.msdn.com/oldnewthing/archive/2004/06/14/155107.aspx
Chad
Win32, HINSTANCE and HMODULE are both just the base address of the module.
Chad
A: 

Calling GetModuleHandle(NULL) from a dll will return the Hinstanc of the EXE that started the DLL; to get the Hinstance for the curently running dll try this tip:

http://www.dotnet247.com/247reference/msgs/13/65259.aspx