Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I get HINSTANCE from a DLL?

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?

like image 772
anand Avatar asked Jan 24 '10 10:01

anand


People also ask

How do I get hInstance?

Just make hInstance = NULL when registering the class and pass NULL to CreateWindow() and you're good to go.

What does hInstance mean?

hInstance is something called a "handle to an instance" or "handle to a module." The operating system uses this value to identify the executable (EXE) when it is loaded in memory. The instance handle is needed for certain Windows functions—for example, to load icons or bitmaps.

What is an HMODULE?

HMODULE. A handle to a module. The is the base address of the module in memory. HMODULE and HINSTANCE are the same in current versions of Windows, but represented different things in 16-bit Windows.


1 Answers

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

like image 166
Swiss Avatar answered Sep 18 '22 14:09

Swiss