Use hModule of DLL or HINSTANCE of mainapp in CreateWindow?

I have a dll in which I create a Popup Window.  In the code for
creating the window I must supply an HINSTANCE to both the
WNDCLASS definition and in the call to CreateWindow().

I am not sure if I should use the HINSTANCE of the main app (which
I send to the dll through a function call), or if I should use the
hModule handle which I get from the DllMain call:

                       DWORD  ul_reason_for_call,
                       LPVOID lpReserved)

From what I understand the hModule HANDLE is the same
as an HINSTANCE. When I use the hModule I simply cast it to

Both techniques seem to work and I don't notice any performance
differences, but I want to make sure I am doing the right thing.
Also, I would prefer to use the hModule of the DLL
so that the main app does not need to pass in it's HINSTANCE.

What is the proper method?

Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Actually, DllMain has the following attributes:

  HINSTANCE hinstDLL,  // handle to DLL module
  DWORD fdwReason,     // reason for calling function
  LPVOID lpvReserved   // reserved

HINSTANCE and HMODULE are the same.

If you create a window inside a dll, you have to specify hinstDll obtained from DllMain.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It may be useful to understand about hInstance

Window Classes in Win32
<<How Does Windows Locate a Class?
When an application creates a window with a specified class, Windows uses the following procedure to find the class:

Windows searches for a local class with the specified name. For the search to be successful, the instance handle for the desired class must match the instance handle for the registered class. This requirement prevents an application local class registered in a DLL from being found by any other DLL or application in that process.>>

So, if you create a class and window inside a dll, specify dll instance handle for both RegisterClass and CreateWindow. Application handle is not required.
kaplan1Author Commented:
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Development

From novice to tech pro — start learning today.