From ab4d315cbd4e5992dce8c095728ca9d99567986e Mon Sep 17 00:00:00 2001 From: Serhiy Storchaka Date: Sun, 9 Aug 2026 16:51:27 +0300 Subject: [PATCH] gh-85470: Delay load ole32.dll in the _ctypes module ole32.dll pulls in user32.dll, which makes the system treat the process as a GUI process and stop sending logoff and shutdown console control events to it. It is only needed for ProgIDFromCLSID() when formatting a COM error. --- .../Windows/2026-08-09-15-40-00.gh-issue-85470.Lm4Xt9.rst | 4 ++++ PCbuild/_ctypes.vcxproj | 1 + 2 files changed, 5 insertions(+) create mode 100644 Misc/NEWS.d/next/Windows/2026-08-09-15-40-00.gh-issue-85470.Lm4Xt9.rst diff --git a/Misc/NEWS.d/next/Windows/2026-08-09-15-40-00.gh-issue-85470.Lm4Xt9.rst b/Misc/NEWS.d/next/Windows/2026-08-09-15-40-00.gh-issue-85470.Lm4Xt9.rst new file mode 100644 index 000000000000000..1d623c890e960b6 --- /dev/null +++ b/Misc/NEWS.d/next/Windows/2026-08-09-15-40-00.gh-issue-85470.Lm4Xt9.rst @@ -0,0 +1,4 @@ +Importing :mod:`ctypes` on Windows no longer loads ``user32.dll``, which +made the system treat the process as a GUI process and stop sending logoff +and shutdown console control events to it. ``ole32.dll``, which pulled +``user32.dll`` in, is now delay loaded. diff --git a/PCbuild/_ctypes.vcxproj b/PCbuild/_ctypes.vcxproj index 63d5fa49cd4e17a..e56d812d78dcd80 100644 --- a/PCbuild/_ctypes.vcxproj +++ b/PCbuild/_ctypes.vcxproj @@ -98,6 +98,7 @@ /EXPORT:DllGetClassObject,PRIVATE /EXPORT:DllCanUnloadNow,PRIVATE %(AdditionalOptions) + ole32.dll