Skip to content

Commit

Permalink
Replace defining GetModuleFileName with importing from typeinfo.
Browse files Browse the repository at this point in the history
  • Loading branch information
junkmd committed Feb 19, 2025
1 parent 0de3a11 commit a65dffb
Showing 1 changed file with 4 additions and 8 deletions.
12 changes: 4 additions & 8 deletions comtypes/client/_code_cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@
import sys
import tempfile
import types
from ctypes.wintypes import HMODULE, MAX_PATH
from ctypes.wintypes import MAX_PATH

from comtypes import typeinfo

logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -85,15 +87,12 @@ def _find_gen_dir():
################################################################

SHGetSpecialFolderPath = ctypes.OleDLL("shell32.dll").SHGetSpecialFolderPathW
GetModuleFileName = ctypes.WinDLL("kernel32.dll").GetModuleFileNameW
SHGetSpecialFolderPath.argtypes = [
ctypes.c_ulong,
ctypes.c_wchar_p,
ctypes.c_int,
ctypes.c_int,
]
GetModuleFileName.restype = ctypes.c_ulong
GetModuleFileName.argtypes = [HMODULE, ctypes.c_wchar_p, ctypes.c_ulong]

CSIDL_APPDATA = 26

Expand Down Expand Up @@ -139,10 +138,7 @@ def _is_writeable(path):
def _get_module_filename(hmodule):
"""Call the Windows GetModuleFileName function which determines
the path from a module handle."""
path = ctypes.create_unicode_buffer(MAX_PATH)
if GetModuleFileName(hmodule, path, MAX_PATH):
return path.value
raise ctypes.WinError()
return typeinfo.GetModuleFileName(hmodule, MAX_PATH)


def _get_appdata_dir():
Expand Down

0 comments on commit a65dffb

Please sign in to comment.