diff --git a/Source/exehead/Main.c b/Source/exehead/Main.c index eb231e77..a3c9b7e7 100644 --- a/Source/exehead/Main.c +++ b/Source/exehead/Main.c @@ -108,9 +108,23 @@ EXTERN_C void NSISWinMainNOCRT() FARPROC fp = myGetProcAddress(MGA_SetDefaultDllDirectories); if (fp) ((BOOL(WINAPI*)(DWORD))fp)(LOAD_LIBRARY_SEARCH_SYSTEM32|LOAD_LIBRARY_SEARCH_USER_DIRS); } - LoadSystemLibrary("UXTHEME"); // On Vista OleInitialize calls NtUserCreateWindowEx and that pulls in UXTheme.dll - LoadSystemLibrary("USERENV"); // On Vista SHGetFileInfo ends up in SHELL32.kfapi::GetUserProfileDir and that pulls in UserEnv.dll - LoadSystemLibrary("SETUPAPI"); // On XP SHGetFileInfo ends up in CMountPoint::_InitLocalDriveHelper and that pulls in SetupAPI.dll + // SetDefaultDllDirectories might not be available so we try to preload various libraries as + // best we can before Windows gets a chance to mess things up by loading from the wrong directory. + { + static const char preload[] = + "UXTHEME\0" // Vista: OleInitialize calls NtUserCreateWindowEx and that pulls in UXTheme.dll + "USERENV\0" // Vista: SHGetFileInfo ends up in SHELL32.kfapi::GetUserProfileDir and that pulls in UserEnv.dll + "SETUPAPI\0" // XP: SHGetFileInfo ends up in CMountPoint::_InitLocalDriveHelper and that pulls in SetupAPI.dll + "APPHELP\0" // Vista: SHGetFileInfo ... SHELL32.SHILAliasTranslate ... SHELL32.ApphelpCheckShellObject + "PROPSYS\0" // Vista: SHGetFileInfo ... SHELL32.SHILAliasTranslate ... SHLWAPI.#187 ... SHLWAPI.#505/SHPropertyBag_ReadGUID + "DWMAPI\0" // Win7 without KB2533623: UXTheme pulls in DWMAPI.dll + "CRYPTBASE\0" // Win7 without KB2533623: OleInitialize ... RPCRT4.UuidCreate ... RPCRT4.GenerateRandomNumber + "OLEACC\0" // Vista: SHFileOperation ... SHELL32.CProgressDialogUI::_Setup ... SHELL32.GetRoleTextW + ; + const char *dll; + for (dll = preload; dll[0]; dll += lstrlenA(dll) + 1) + LoadSystemLibrary(dll); + } } // Because myGetProcAddress now loads dlls with a full path diff --git a/Source/exehead/util.c b/Source/exehead/util.c index e9152139..8dc73b4b 100644 --- a/Source/exehead/util.c +++ b/Source/exehead/util.c @@ -1139,7 +1139,7 @@ HMODULE NSISCALL LoadSystemLibrary(LPCSTR name) cch = 0; // \\?\ paths so we have to settle for just the name. wsprintf(path + cch, fmt, TEXT("\\") + (!cch || path[cch-1] == '\\'), name); - return LoadLibrary(path); + return LoadLibraryEx(path, NULL, LOAD_WITH_ALTERED_SEARCH_PATH); } /**