From 0a05d2f578dadf50b7a8713cb704e6199e082493 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Fri, 6 Sep 2019 10:32:48 +0530 Subject: [PATCH] Disabe SetDllDirectories on 32bit builds since it causes a crash --- bypy/windows/__main__.py | 22 ++++++++++++++++++++++ bypy/windows/main.c | 4 ++++ 2 files changed, 26 insertions(+) diff --git a/bypy/windows/__main__.py b/bypy/windows/__main__.py index 5a92e87600..7eee5facb5 100644 --- a/bypy/windows/__main__.py +++ b/bypy/windows/__main__.py @@ -723,5 +723,27 @@ def main(): sign_installers(env) +def develop_launcher(): + import subprocess + + def r(*a): + subprocess.check_call(list(a)) + + r( + 'cl.EXE', '/c', '/EHsc', '/MT', '/W3', '/O1', '/nologo', '/D_UNICODE', '/DUNICODE', '/GS-', + '/DMODULE="calibre.debug"', '/DBASENAME="calibre-debug"', '/DFUNCTION="main"', + r'/TcC:\r\src\bypy\windows\main.c', r'/Fo..\launcher\calibre-debug.obj' + ) + r( + 'link.EXE', '/MACHINE:X86', '/NODEFAULTLIB', '/ENTRY:start_here', + r'/LIBPATH:..\launcher', '/SUBSYSTEM:CONSOLE', + r'/LIBPATH:C:\r\sw32\sw\private\python/libs', '/RELEASE', + '/MANIFEST:EMBED', r'/MANIFESTINPUT:..\launcher\calibre-debug.obj.manifest', + 'user32.lib', 'kernel32.lib', r'/OUT:calibre-debug.exe', + 'user32.lib', '/INCREMENTAL:NO', r'..\launcher\calibre-debug.exe.res', + r'..\launcher\calibre-debug.obj', r'..\launcher\calibre-launcher.lib' + ) + + if __name__ == '__main__': main() diff --git a/bypy/windows/main.c b/bypy/windows/main.c index 6bc83285cd..790c458f33 100644 --- a/bypy/windows/main.c +++ b/bypy/windows/main.c @@ -80,9 +80,13 @@ load_launcher_dll() { return; } wsprintf(dll_point, L"%s\0\0", L"app\\bin"); +#if _WIN64 // Restrict the directories from which DLLs can be loaded + // For some reason I cannot determine, using this in 32bit builds causes + // a crash even if no dlls are loaded. SETDEFAULTDIRS SetDefaultDllDirectories = (SETDEFAULTDIRS)GetProcAddress(GetModuleHandleW(L"kernel32.dll"), "SetDefaultDllDirectories"); if (SetDefaultDllDirectories) SetDefaultDllDirectories(LOAD_LIBRARY_SEARCH_DEFAULT_DIRS); +#endif if (SetDllDirectoryW(buf) == 0) { show_last_error(L"Failed to set DLL directory"); return;