Link to home
Start Free TrialLog in
Avatar of kaplan1
kaplan1

asked on

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:

BOOL APIENTRY DllMain( HANDLE hModule,
                       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
an HINSTANCE.

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?


ASKER CERTIFIED SOLUTION
Avatar of NickRepin
NickRepin

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of NickRepin
NickRepin

It may be useful to understand about hInstance

Window Classes in Win32
http://msdn.microsoft.com/library/techart/msdn_classy32.htm
<<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.
Avatar of kaplan1

ASKER

Thanks!