Skip to content

Commit ed2f9e7

Browse files
committed
Clarify GetModuleFileNameW behavior in virtual environments.
1 parent c9f5238 commit ed2f9e7

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

comtypes/typeinfo.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -768,6 +768,10 @@ def GetModuleFileName(handle: Optional[int], maxsize: int) -> str:
768768
https://learn.microsoft.com/en-us/windows/win32/api/libloaderapi/nf-libloaderapi-getmodulefilenamew
769769
"""
770770
buf = create_unicode_buffer(maxsize)
771+
# In a Python virtual environment on Windows, the Windows API
772+
# `GetModuleFileNameW(NULL, ..., ...)` returns the path to the base
773+
# `python.exe` (located within `sys.base_prefix`, not same as
774+
# `sys.executable`).
771775
length = _GetModuleFileNameW(handle, buf, maxsize)
772776
if not length:
773777
raise ctypes.WinError()

0 commit comments

Comments
 (0)