From: Luke D. <cod...@ho...> - 2003-07-04 07:08:37
|
----- Original Message ----- From: "Chris Sutcliffe" <iro...@ro...> To: <min...@li...> Sent: Friday, July 04, 2003 11:25 AM Subject: [Mingw-users] Global Hooks > Hey All, > > I'm having a hard time getting a global hook to work. Here's the > relevant sections of the DLL code: > > HINSTANCE hInstance = NULL; > > BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID > lpvReserved) > { > hInstance = hinstDLL; > return TRUE; > } > > void SetDesktopMouseHook(HWND iDeskWnd, HMENU iDeskMenu) > { > deskWnd = iDeskWnd; > deskMenu = iDeskMenu; > hDeskHook = SetWindowsHookEx(WH_MOUSE, MouseProc, hInstance, > 0); > if (hDeskHook) > MessageBox(GetDesktopWindow(), "Hook Successful", > "DeskHook", MB_OK | MB_TOPMOST); > else > MessageBox(GetDesktopWindow(), "Hook Failed", > "DeskHook", MB_OK | MB_TOPMOST); > } > > The hook always fails. I've managed to get local hooks to work (using > the thread of the local process), and this code works (with the addition > of some pragma sections) in MSVC. What pragmas? > I'm assuming that since the code > works in MSVC and local hooks work MinGW, it could be something I'm > going wrong in the Makefile? I don't think so. Try using a debugger to step into SetDesktopMouseHook and see whether hInstance is actually set, because if not then DllMain() is not being invoked (of course you could also check this in the code instead of the debugger), and you might try declaring DllMain() as extern "C". If that is the problem, then the reason why it works with MSVC is probably because their linker does funny things like looking for the C++ mangled name of DllMain() if the C name is not found. Luke > > Here's what my Makefile consists of: > > CC=g++ > CFLAGS=-shared -Wall -std=c++98 -pedantic -mno-cygwin > -DWIN32_LEAN_AND_MEAN -DBUILD_DLL > SRCS=DeskHook.cpp > > release: > $(CC) -O2 $(CFLAGS) -Wl,--out-implib,../Lib/libDeskHook.a -o > ../Release/DeskHook.dll $(SRCS) -L../Lib -liLib > > If anyone could help it would be greatly appreciated. I'm really at a > loss with this one.... > > Thanx! > > Chris > > --- > iro...@ro... > http://ishell.sourceforge.net > http://shellwm.sourceforge.net > http://bb4win.org |