From 6feee2e3c29effa7775c5059de119c12321db3c8 Mon Sep 17 00:00:00 2001 From: Roberto Pastor Muela <37798125+RobPasMue@users.noreply.github.com> Date: Wed, 6 Nov 2024 13:47:57 +0100 Subject: [PATCH] fix: Windows DLL proper load --- src/ansys/tools/installer/main.py | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/src/ansys/tools/installer/main.py b/src/ansys/tools/installer/main.py index 698d965a..b36d4316 100644 --- a/src/ansys/tools/installer/main.py +++ b/src/ansys/tools/installer/main.py @@ -739,13 +739,29 @@ def _run_install_python(self, filename): self.setEnabled(True) +def __restore_windows_dll_load(): + """PyInstaller on Windows may break DLL loading. This function restores it.""" + import sys + LOG.debug(f"sys.platform: {sys.platform}") + if sys.platform == "win32": + LOG.debug("Restoring DLL loading on Windows...") + import ctypes + ctypes.windll.kernel32.SetDllDirectoryA(None) + + def open_gui(): """Start the installer as a QT Application.""" import argparse import ctypes + + # Enable logging early + enable_logging() if os.name == "nt": import msvcrt + + # Restore DLL loading on Windows... + __restore_windows_dll_load() kernel32 = ctypes.windll.kernel32 @@ -776,8 +792,6 @@ def open_gui(): sys.stdout = open("CONOUT$", "w") sys.stderr = open("CONOUT$", "w") - enable_logging() - app = QtWidgets.QApplication(sys.argv) window = AnsysPythonInstaller()