[USER] 'Fix' SetWindowsHookEx

Lionel Ulmer lionel.ulmer at free.fr
Sat Jun 12 10:33:38 CDT 2004


Hi all,

A pretty old game (Theme Hospital - the Win95 version, not the DOS one)
fails at start-up due to the SetWindowsHookExA returning 0. This is because
the game is explicitely giving NULL as the third parameter (the HINSTANCE
hMod parameter from MSDN). This is not supported by Wine which returned an
error.

I have actually no idea what exactly is what Windows is doing there, but
this attached patch seems to do the trick. I have no idea if it's correct
though (as I do not know if what GetModuleHandle returns is really the same
thing as what SetWindowsHookEx expects as an HINSTANCE input).

             Lionel

Changelog: 
  allow to have a NULL instance parameter in the SetWindowsHookEx procedure

-- 
		 Lionel Ulmer - http://www.bbrox.org/
-------------- next part --------------
Index: dlls/user/hook.c
===================================================================
RCS file: /home/wine/wine/dlls/user/hook.c,v
retrieving revision 1.12
diff -u -r1.12 hook.c
--- dlls/user/hook.c	19 May 2004 03:22:55 -0000	1.12
+++ dlls/user/hook.c	12 Jun 2004 15:27:01 -0000
@@ -141,11 +141,15 @@
     else  /* system-global hook */
     {
         if (id == WH_KEYBOARD_LL || id == WH_MOUSE_LL) inst = 0;
-        else if (!inst || !(len = GetModuleFileNameW( inst, module, MAX_PATH )) || len >= MAX_PATH)
-        {
-            SetLastError( ERROR_INVALID_PARAMETER );
-            return 0;
-        }
+	else
+	{
+	    if (!inst) inst = GetModuleHandleW(NULL);
+	    if (!inst || !(len = GetModuleFileNameW( inst, module, MAX_PATH )) || len >= MAX_PATH)
+	    {
+		SetLastError( ERROR_INVALID_PARAMETER );
+		return 0;
+	    }
+	}
     }
 
     SERVER_START_REQ( set_hook )


More information about the wine-patches mailing list