user32: Fix hook_proc DLL loading using LoadLibraryExW instead of LoadLibraryW

Hongbo Ni hongbo at
Wed Aug 20 01:28:27 CDT 2008

This patch fixes Bug 14784.

As requested by Dmitry Timoshkov, I have created a standalone test case 
for DLL injection via SetWindowHookEx. It has been attached in Bug 14784 
with MSVC source code and compiled exe and dll.

With LoadLibraryExW(module, NULL, LOAD_WITH_ALTERED_SEARCH_PATH), the 
Wine will search any imported DLL first in the same directory as module, 
then in the standard search path.

LoadLibraryW(module) searches imported DLL(s) in the directory of current 
process, which may not be the same process where the module is first 
loaded. That is why that LoadLibraryW(module) fails to hook to another 
process if the DLL containing the hook_proc links to another DLL(s) in 
the same directory.

 dlls/user32/hook.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/dlls/user32/hook.c b/dlls/user32/hook.c
index 4354e05..638a302 100644
--- a/dlls/user32/hook.c
+++ b/dlls/user32/hook.c
@@ -322,7 +322,7 @@ void *get_hook_proc( void *proc, const WCHAR *module )
         TRACE( "loading %s\n", debugstr_w(module) );
         /* FIXME: the library will never be freed */
-        if (!(mod = LoadLibraryW(module))) return NULL;
+        if (!(mod = LoadLibraryExW(module, NULL, LOAD_WITH_ALTERED_SEARCH_PATH))) return NULL;
     return (char *)mod + (ULONG_PTR)proc;

More information about the wine-patches mailing list