Question: 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?

Answer: 
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](https://web.archive.org/web/20120322043832/http://www.dotnet247.com/247reference/msgs/13/65259.aspx)
To complement the other answers, for the sake of completness.

The actual signature of `DllMain` has an `HINSTANCE` parameter, instead of a `HMODULE` parameter. The Visual Studio DLL template generates the signature with `HMODULE` since at least Visual Studio 2008 however, but I believe this to be a minor bug more than anything. VC6 generated the code with `HANDLE` (even though both `HINSTANCE` and `HMODULE` exist). The reason that doesn't cause problems is because [`HINSTANCE` and `HMODULE` are now exactly the same thing](https://devblogs.microsoft.com/oldnewthing/20040614-00/?p=38903). Unfortunately I was unable to find an ancient enough version of the MSDN documetnation that could have confirmed this.

So the answer is: **You get your `HINSTANCE` as an argument to your `DllMain`.**

Personally I sort of like the distinction between HMODULE and HINSTANCE because it appeals to me as being good code hygiene. It's a bit like using `const`. But then, a new question arises: **Given your `HINSTANCE`, how do you get your `HMODULE`** in the "hygienic" way?

The `windowsx.h` header defines `GetInstanceModule`, which is now a macro that just casts the `HINSTANCE` to `HMODULE`. It only exists for code compatibility, along with a bunch of very similar macros.