How to inport a win32 dll and get HWND parents
-
wrote on 30 Apr 2015, 15:44 last edited by
I want use a win32 dll file in my project .I am using MinGW compiler.how can import my dll into my project and use its functions.
My dll have functions that need HWND parent windows. Can i use an Widget as window for HWND and how can i get HWND of a widget.
Can anybody help me.I have a api header file for my dll. -
wrote on 30 Apr 2015, 16:44 last edited by
Hi ahmet4697,
if you just have the dll and no import library you have to use the winapi functions
LoadLibrary
andGetProcAddress
to call the functions inside the dll.The
winID()
member function of your widget will return aWId
, that can be cast toHWND
. TheWId
may change at run-time. Catch theWinIdChange
event to update yourHWND
. -
wrote on 30 Apr 2015, 23:28 last edited by
It depends on the reason for the DLL to need the HWND value and how it uses it.
If, for example, the DLL uses SendMessage() to talk to the parent window then your DLL won't work properly without the message loop. There may be other reasons for passing the HWND value but likely this is the primary reason.
For this scenerio what I have done is to register a window class and create a dummy hidden window, When you register the window class you will pass the call back function as one of the parameters. When you create the window all messages that belong to this window are sent to the call back function. Just add what is needed there.
if the winID() function actually returns a HWND value (to a window class you know nothing about) you could install a message hook and monitor for messages that you need access to.
Maybe the HWND value is not required for anything important in which case why not pass NULL to the DLL?.
If you use 'LoadLibrary' you should make sure your DLL doesn't have the names mangled. In the DLL the exported functions should be decorated something like this:
// BOOL Non_Manged_Name(DWORD); external "C" __declspec(dllexport) BOOL __cdecl Non_Mangled_Name(DWORD data);
1/3