Skip to content

Commit

Permalink
Replace client._code_cache._get_module_filename with `typeinfo.GetM…
Browse files Browse the repository at this point in the history
…oduleFileName`.
  • Loading branch information
junkmd committed Feb 19, 2025
1 parent a65dffb commit 2354141
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 10 deletions.
8 changes: 1 addition & 7 deletions comtypes/client/_code_cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ def _find_gen_dir():

elif ftype == "dll":
# dll created with py2exe
path = _get_module_filename(sys.frozendllhandle)
path = typeinfo.GetModuleFileName(sys.frozendllhandle, MAX_PATH)
base = os.path.splitext(os.path.basename(path))[0]
subdir = rf"comtypes_cache\{base}-{pymaj:d}{pymin:d}"
basedir = tempfile.gettempdir()
Expand Down Expand Up @@ -135,12 +135,6 @@ def _is_writeable(path):
return os.access(path[0], os.W_OK)


def _get_module_filename(hmodule):
"""Call the Windows GetModuleFileName function which determines
the path from a module handle."""
return typeinfo.GetModuleFileName(hmodule, MAX_PATH)


def _get_appdata_dir():
"""Return the 'file system directory that serves as a common
repository for application-specific data' - CSIDL_APPDATA"""
Expand Down
5 changes: 2 additions & 3 deletions comtypes/tools/tlbparser.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import sys
from _ctypes import COMError
from ctypes import alignment, c_void_p, sizeof, windll
from ctypes.wintypes import MAX_PATH
from typing import Any, Dict, List, Optional, Tuple

from comtypes import automation, typeinfo
Expand Down Expand Up @@ -750,9 +751,7 @@ def get_tlib_filename(tlib: typeinfo.ITypeLib) -> Optional[str]:
# workaround Windows 7 bug in QueryPathOfRegTypeLib returning relative path
try:
dll = windll.LoadLibrary(full_filename)
from comtypes.client._code_cache import _get_module_filename

full_filename = _get_module_filename(dll._handle)
full_filename = typeinfo.GetModuleFileName(dll._handle, MAX_PATH)
del dll
except OSError:
return None
Expand Down

0 comments on commit 2354141

Please sign in to comment.