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: 
Each DLL has at least a header file, say MyDll.h and a corresponding implementation file MyDll.cpp. Open the header file and add

```
extern HMODULE hDllModule;//or whatever name you like 

```

Now open the MyDll.cpp file. There is a function DLLMAIN. Add before it `HMODULE hDllModule;` and insert `hDllModuleDll = hModule;` before `return true;`. Your code will look like this:

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

```

In functions like `::GetModuleFileNameW(hModule, PathFile, MAX_PATH);` that require a `HMODULE` of the DLL you can pass the global variable `hDllModule`.
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.