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: 
An excerpt from the book Windows Via C/C++ [1]

> 
> **Note** As it turns out, **HMODULE**s and **HINSTANCE**s 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 **HMODULE**s and **HINSTANCE**s identified different things
> 
> 
> 

[1] Richter, Jeffery and Nasarre, Christophe, *Windows Via C/C++*, 5th ed, Redmond: Microsoft Press 2008, pp. 74
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`.