diff --git a/controls/edit.c b/controls/edit.c index 377a8d4db9a..82b289ca95c 100644 --- a/controls/edit.c +++ b/controls/edit.c @@ -3688,7 +3688,7 @@ static void EDIT_WM_Command(EDITSTATE *es, INT code, INT id, HWND control) */ static void EDIT_WM_ContextMenu(EDITSTATE *es, INT x, INT y) { - HMENU menu = LoadMenuA(GetModuleHandleA("USER32"), "EDITMENU"); + HMENU menu = LoadMenuA(user32_module, "EDITMENU"); HMENU popup = GetSubMenu(menu, 0); UINT start = es->selection_start; UINT end = es->selection_end; diff --git a/controls/menu.c b/controls/menu.c index b565f087924..a068e8e7393 100644 --- a/controls/menu.c +++ b/controls/menu.c @@ -328,9 +328,8 @@ static HMENU get_win_sys_menu( HWND hwnd ) */ static HMENU MENU_CopySysPopup(void) { - static const WCHAR user32W[] = {'U','S','E','R','3','2',0}; static const WCHAR sysmenuW[] = {'S','Y','S','M','E','N','U',0}; - HMENU hMenu = LoadMenuW(GetModuleHandleW(user32W), sysmenuW); + HMENU hMenu = LoadMenuW(user32_module, sysmenuW); if( hMenu ) { POPUPMENU* menu = MENU_GetMenu(hMenu); diff --git a/dlls/commdlg/colordlg16.c b/dlls/commdlg/colordlg16.c index 0159e47a7b3..8733452226a 100644 --- a/dlls/commdlg/colordlg16.c +++ b/dlls/commdlg/colordlg16.c @@ -442,7 +442,7 @@ BOOL16 WINAPI ChooseColor16( LPCHOOSECOLOR16 lpChCol ) COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE); return FALSE; } - size = SizeofResource(GetModuleHandleA("COMDLG32"), hResInfo); + size = SizeofResource(COMDLG32_hInstance, hResInfo); hGlobal16 = GlobalAlloc16(0, size); if (!hGlobal16) { diff --git a/dlls/commdlg/filedlg16.c b/dlls/commdlg/filedlg16.c index 063a9c0281b..dac494f2f1e 100644 --- a/dlls/commdlg/filedlg16.c +++ b/dlls/commdlg/filedlg16.c @@ -95,18 +95,12 @@ static BOOL FileDlg_Init(void) static BOOL initialized = 0; if (!initialized) { - HINSTANCE inst = GetModuleHandleA( "comdlg32.dll" ); - if (!inst) - { - ERR( "cannot get comdlg32.dll instance\n" ); - return FALSE; - } - hFolder = LoadImageA( inst, "FOLDER", IMAGE_ICON, 16, 16, LR_SHARED ); - hFolder2 = LoadImageA( inst, "FOLDER2", IMAGE_ICON, 16, 16, LR_SHARED ); - hFloppy = LoadImageA( inst, "FLOPPY", IMAGE_ICON, 16, 16, LR_SHARED ); - hHDisk = LoadImageA( inst, "HDISK", IMAGE_ICON, 16, 16, LR_SHARED ); - hCDRom = LoadImageA( inst, "CDROM", IMAGE_ICON, 16, 16, LR_SHARED ); - hNet = LoadImageA( inst, "NETWORK", IMAGE_ICON, 16, 16, LR_SHARED ); + hFolder = LoadImageA( COMDLG32_hInstance, "FOLDER", IMAGE_ICON, 16, 16, LR_SHARED ); + hFolder2 = LoadImageA( COMDLG32_hInstance, "FOLDER2", IMAGE_ICON, 16, 16, LR_SHARED ); + hFloppy = LoadImageA( COMDLG32_hInstance, "FLOPPY", IMAGE_ICON, 16, 16, LR_SHARED ); + hHDisk = LoadImageA( COMDLG32_hInstance, "HDISK", IMAGE_ICON, 16, 16, LR_SHARED ); + hCDRom = LoadImageA( COMDLG32_hInstance, "CDROM", IMAGE_ICON, 16, 16, LR_SHARED ); + hNet = LoadImageA( COMDLG32_hInstance, "NETWORK", IMAGE_ICON, 16, 16, LR_SHARED ); if (hFolder == 0 || hFolder2 == 0 || hFloppy == 0 || hHDisk == 0 || hCDRom == 0 || hNet == 0) { @@ -230,7 +224,7 @@ BOOL Get16BitsTemplate(LFSPRIVATE lfs) COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE); return FALSE; } - size = SizeofResource(GetModuleHandleA("COMDLG32"), hResInfo); + size = SizeofResource(COMDLG32_hInstance, hResInfo); hGlobal16 = GlobalAlloc16(0, size); if (!hGlobal16) { diff --git a/dlls/commdlg/finddlg.c b/dlls/commdlg/finddlg.c index 70e8ad4f1c9..afaa3743c38 100644 --- a/dlls/commdlg/finddlg.c +++ b/dlls/commdlg/finddlg.c @@ -121,7 +121,7 @@ BOOL FINDDLG_Get16BitsTemplate(LFRPRIVATE lfr) COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE); return FALSE; } - size = SizeofResource(GetModuleHandleA("COMDLG32"), hResInfo); + size = SizeofResource(COMDLG32_hInstance, hResInfo); hGlobal16 = GlobalAlloc16(0, size); if (!hGlobal16) { diff --git a/dlls/commdlg/fontdlg16.c b/dlls/commdlg/fontdlg16.c index bb10e40ed7f..b1ab2b3388b 100644 --- a/dlls/commdlg/fontdlg16.c +++ b/dlls/commdlg/fontdlg16.c @@ -205,7 +205,7 @@ BOOL16 WINAPI ChooseFont16(LPCHOOSEFONT16 lpChFont) COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE); return FALSE; } - size = SizeofResource(GetModuleHandleA("COMDLG32"), hResInfo); + size = SizeofResource(COMDLG32_hInstance, hResInfo); hGlobal16 = GlobalAlloc16(0, size); if (!hGlobal16) { diff --git a/dlls/opengl32/wgl.c b/dlls/opengl32/wgl.c index 71d6f9c4279..4f1fb91e402 100644 --- a/dlls/opengl32/wgl.c +++ b/dlls/opengl32/wgl.c @@ -52,6 +52,8 @@ void (*wine_tsx11_unlock_ptr)(void) = NULL; static GLXContext default_cx = NULL; static Display *default_display; /* display to use for default context */ +static HMODULE opengl32_handle; + static void *(*p_glXGetProcAddressARB)(const GLubyte *); typedef struct wine_glcontext { @@ -310,18 +312,13 @@ static int wgl_compar(const void *elt_a, const void *elt_b) { void* WINAPI wglGetProcAddress(LPCSTR lpszProc) { void *local_func; - static HMODULE hm = 0; OpenGL_extension ext; OpenGL_extension *ext_ret; - TRACE("(%s)\n", lpszProc); - if (hm == 0) - hm = GetModuleHandleA("opengl32"); - /* First, look if it's not already defined in the 'standard' OpenGL functions */ - if ((local_func = GetProcAddress(hm, lpszProc)) != NULL) { + if ((local_func = GetProcAddress(opengl32_handle, lpszProc)) != NULL) { TRACE(" found function in 'standard' OpenGL functions (%p)\n", local_func); return local_func; } @@ -397,7 +394,7 @@ void* WINAPI wglGetProcAddress(LPCSTR lpszProc) { buf[strlen(ext_ret->glx_name) - 3] = '\0'; TRACE(" extension not found in the Linux OpenGL library, checking against libGL bug with %s..\n", buf); - ret = GetProcAddress(hm, buf); + ret = GetProcAddress(opengl32_handle, buf); if (ret != NULL) { TRACE(" found function in main OpenGL library (%p) !\n", ret); } else { @@ -775,6 +772,7 @@ BOOL WINAPI DllMain( HINSTANCE hinst, DWORD reason, LPVOID reserved ) switch(reason) { case DLL_PROCESS_ATTACH: + opengl32_handle = hinst; DisableThreadLibraryCalls(hinst); return process_attach(); case DLL_PROCESS_DETACH: diff --git a/dlls/user/user_main.c b/dlls/user/user_main.c index d3add4713bb..ee52fcf14e0 100644 --- a/dlls/user/user_main.c +++ b/dlls/user/user_main.c @@ -42,6 +42,7 @@ USER_DRIVER USER_Driver; WINE_LOOK TWEAK_WineLook = WIN31_LOOK; WORD USER_HeapSel = 0; /* USER heap selector */ +HMODULE user32_module = 0; extern HPALETTE (WINAPI *pfnGDISelectPalette)(HDC hdc, HPALETTE hpal, WORD bkgnd ); extern UINT (WINAPI *pfnGDIRealizePalette)(HDC hdc); @@ -183,7 +184,7 @@ static void tweak_init(void) /*********************************************************************** * USER initialisation routine */ -static BOOL process_attach( HINSTANCE inst ) +static BOOL process_attach(void) { HINSTANCE16 instance; @@ -207,7 +208,7 @@ static BOOL process_attach( HINSTANCE inst ) palette_init(); /* Initialize built-in window classes */ - CLASS_RegisterBuiltinClasses( inst ); + CLASS_RegisterBuiltinClasses(); /* Initialize menus */ if (!MENU_Init()) return FALSE; @@ -268,7 +269,8 @@ BOOL WINAPI DllMain( HINSTANCE inst, DWORD reason, LPVOID reserved ) switch(reason) { case DLL_PROCESS_ATTACH: - ret = process_attach( inst ); + user32_module = inst; + ret = process_attach(); break; case DLL_THREAD_DETACH: thread_detach(); diff --git a/dlls/user/winproc.h b/dlls/user/winproc.h index 3b794f45ead..a0de1e85dbe 100644 --- a/dlls/user/winproc.h +++ b/dlls/user/winproc.h @@ -138,7 +138,7 @@ inline static void unmap_str_16_to_32W( LPCWSTR str ) /* Class functions */ struct tagCLASS; /* opaque structure */ struct tagWND; -extern void CLASS_RegisterBuiltinClasses( HINSTANCE inst ); +extern void CLASS_RegisterBuiltinClasses(void); extern void CLASS_AddWindow( struct tagCLASS *class, struct tagWND *win, WINDOWPROCTYPE type ); extern void CLASS_FreeModuleClasses( HMODULE16 hModule ); diff --git a/include/user.h b/include/user.h index c35241e69fd..28229ab8e31 100644 --- a/include/user.h +++ b/include/user.h @@ -127,6 +127,8 @@ typedef struct tagUSER_DRIVER { extern USER_DRIVER USER_Driver; +extern HMODULE user32_module; + /* user lock */ extern void USER_Lock(void); extern void USER_Unlock(void); diff --git a/windows/class.c b/windows/class.c index 19ae8069000..f01f6059dd5 100644 --- a/windows/class.c +++ b/windows/class.c @@ -68,7 +68,6 @@ typedef struct tagCLASS static struct list class_list = LIST_INIT( class_list ); static CLASS *desktop_class; -static HMODULE user32_module; #define CLASS_OTHER_PROCESS ((CLASS *)1) @@ -471,7 +470,7 @@ static CLASS *register_builtin( const struct builtin_class_descr *descr ) /*********************************************************************** * CLASS_RegisterBuiltinClasses */ -void CLASS_RegisterBuiltinClasses( HMODULE user32 ) +void CLASS_RegisterBuiltinClasses(void) { extern const struct builtin_class_descr BUTTON_builtin_class; extern const struct builtin_class_descr COMBO_builtin_class; @@ -486,7 +485,6 @@ void CLASS_RegisterBuiltinClasses( HMODULE user32 ) extern const struct builtin_class_descr SCROLL_builtin_class; extern const struct builtin_class_descr STATIC_builtin_class; - user32_module = user32; desktop_class = register_builtin( &DESKTOP_builtin_class ); register_builtin( &BUTTON_builtin_class ); register_builtin( &COMBO_builtin_class ); diff --git a/windows/cursoricon.c b/windows/cursoricon.c index 9f0d7b3e3dd..ded5ab52b01 100644 --- a/windows/cursoricon.c +++ b/windows/cursoricon.c @@ -814,10 +814,7 @@ static HICON CURSORICON_Load(HINSTANCE hInstance, LPCWSTR name, WORD wResId; DWORD dwBytesInRes; - if (!hInstance) /* Load OEM cursor/icon */ - { - if (!(hInstance = GetModuleHandleA( "user32.dll" ))) return 0; - } + if (!hInstance) hInstance = user32_module; /* Load OEM cursor/icon */ /* Normalize hInstance (must be uniquely represented for icon cache) */ @@ -1996,7 +1993,7 @@ static HBITMAP BITMAP_Load( HINSTANCE instance,LPCWSTR name, UINT loadflags ) { /* OEM bitmap: try to load the resource from user32.dll */ if (HIWORD(name)) return 0; - if (!(instance = GetModuleHandleA("user32.dll"))) return 0; + instance = user32_module; } if (!(hRsrc = FindResourceW( instance, name, (LPWSTR)RT_BITMAP ))) return 0; if (!(handle = LoadResource( instance, hRsrc ))) return 0; diff --git a/windows/mdi.c b/windows/mdi.c index 9cb033e0a4f..f3ee2ae44ab 100644 --- a/windows/mdi.c +++ b/windows/mdi.c @@ -397,7 +397,7 @@ static LRESULT MDI_RefreshMenu(MDICLIENTINFO *ci) if (visible == MDI_MOREWINDOWSLIMIT) { - LoadStringW(GetModuleHandleA("USER32"), IDS_MDI_MOREWINDOWS, buf, sizeof(buf)/sizeof(WCHAR)); + LoadStringW(user32_module, IDS_MDI_MOREWINDOWS, buf, sizeof(buf)/sizeof(WCHAR)); AppendMenuW(ci->hWindowMenu, MF_STRING, id, buf); break; } @@ -1917,12 +1917,12 @@ static HWND MDI_MoreWindowsDialog(HWND hwnd) HRSRC hRes; HANDLE hDlgTmpl; - hRes = FindResourceA(GetModuleHandleA("USER32"), "MDI_MOREWINDOWS", (LPSTR)RT_DIALOG); + hRes = FindResourceA(user32_module, "MDI_MOREWINDOWS", (LPSTR)RT_DIALOG); if (hRes == 0) return 0; - hDlgTmpl = LoadResource(GetModuleHandleA("USER32"), hRes ); + hDlgTmpl = LoadResource(user32_module, hRes ); if (hDlgTmpl == 0) return 0; @@ -1932,7 +1932,7 @@ static HWND MDI_MoreWindowsDialog(HWND hwnd) if (template == 0) return 0; - return (HWND) DialogBoxIndirectParamA(GetModuleHandleA("USER32"), + return (HWND) DialogBoxIndirectParamA(user32_module, (LPDLGTEMPLATEA) template, hwnd, MDI_MoreWindowsDlgProc, (LPARAM) hwnd); } diff --git a/windows/msgbox.c b/windows/msgbox.c index f0b17418de9..b40b91677f1 100644 --- a/windows/msgbox.c +++ b/windows/msgbox.c @@ -72,7 +72,7 @@ static HFONT MSGBOX_OnInit(HWND hwnd, LPMSGBOXPARAMSW lpmb) } else { - if (LoadStringW(GetModuleHandleA("user32.dll"), IDS_ERROR, buf, 256)) + if (LoadStringW(user32_module, IDS_ERROR, buf, 256)) SetWindowTextW(hwnd, buf); } } @@ -443,14 +443,12 @@ INT WINAPI MessageBoxIndirectW( LPMSGBOXPARAMSW msgbox ) { LPVOID tmplate; HRSRC hRes; - HMODULE hUser32; - static const WCHAR user32_res_nameW[] = { 'u','s','e','r','3','2','.','d','l','l',0 }; static const WCHAR msg_box_res_nameW[] = { 'M','S','G','B','O','X',0 }; - hUser32 = GetModuleHandleW(user32_res_nameW); - if (!(hRes = FindResourceExW(hUser32, (LPWSTR)RT_DIALOG, msg_box_res_nameW, msgbox->dwLanguageId))) + if (!(hRes = FindResourceExW(user32_module, (LPWSTR)RT_DIALOG, + msg_box_res_nameW, msgbox->dwLanguageId))) return 0; - if (!(tmplate = (LPVOID)LoadResource(hUser32, hRes))) + if (!(tmplate = (LPVOID)LoadResource(user32_module, hRes))) return 0; return DialogBoxIndirectParamW(msgbox->hInstance, tmplate, msgbox->hwndOwner,