Skip to content

Commit fae2869

Browse files
committed
Rename from ...W to GetModuleFileName and small fixes.
1 parent f2646df commit fae2869

File tree

4 files changed

+10
-10
lines changed

4 files changed

+10
-10
lines changed

comtypes/server/register.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,9 @@
5050
from comtypes.server import w_getopt
5151
from comtypes.typeinfo import (
5252
REGKIND_REGISTER,
53+
GetModuleFileName,
5354
LoadTypeLibEx,
5455
UnRegisterTypeLib,
55-
GetModuleFileNameW,
5656
)
5757

5858
_debug = logging.getLogger(__name__).debug
@@ -225,7 +225,7 @@ def _get_serverdll():
225225
"""Return the pathname of the dll hosting the COM object."""
226226
handle = getattr(sys, "frozendllhandle", None)
227227
if handle is not None:
228-
return GetModuleFileNameW(handle, 260)
228+
return GetModuleFileName(handle, 260)
229229
import _ctypes
230230

231231
return _ctypes.__file__

comtypes/test/test_server_register.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ class Test_get_serverdll(ut.TestCase):
193193
def test_nonfrozen(self):
194194
self.assertEqual(_ctypes.__file__, _get_serverdll())
195195

196-
@mock.patch.object(register, "GetModuleFileNameW")
196+
@mock.patch.object(register, "GetModuleFileName")
197197
@mock.patch.object(register, "sys")
198198
def test_frozen(self, _sys, GetModuleFileName):
199199
handle, dll_path = 1234, r"path\to\frozendll"

comtypes/test/test_typeinfo.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
from comtypes.typeinfo import (
77
TKIND_DISPATCH,
88
TKIND_INTERFACE,
9-
GetModuleFileNameW,
9+
GetModuleFileName,
1010
LoadRegTypeLib,
1111
LoadTypeLibEx,
1212
QueryPathOfRegTypeLib,
@@ -94,16 +94,16 @@ def test_TypeInfo(self):
9494
self.assertEqual(guid, ti.GetTypeAttr().guid)
9595

9696

97-
class Test_GetModuleFileNameW(unittest.TestCase):
97+
class Test_GetModuleFileName(unittest.TestCase):
9898
def test_null_handler(self):
99-
self.assertEqual(GetModuleFileNameW(None, 260), sys.executable)
99+
self.assertEqual(GetModuleFileName(None, 260), sys.executable)
100100

101101
def test_loaded_module_handle(self):
102102
import _ctypes
103103

104104
dll_path = _ctypes.__file__
105105
hmodule = ctypes.WinDLL(dll_path)._handle
106-
self.assertEqual(GetModuleFileNameW(hmodule, 260), dll_path)
106+
self.assertEqual(GetModuleFileName(hmodule, 260), dll_path)
107107

108108

109109
if __name__ == "__main__":

comtypes/typeinfo.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -700,15 +700,15 @@ def QueryPathOfRegTypeLib(
700700
_GetModuleFileNameW.restype = DWORD
701701

702702

703-
def GetModuleFileNameW(handle: Optional[int], maxsize: int) -> str:
703+
def GetModuleFileName(handle: Optional[int], maxsize: int) -> str:
704704
"""Returns the fullpath of the loaded module specified by the handle.
705705
If the handle is NULL, returns the executable file path of the current process.
706706
707707
https://learn.microsoft.com/ja-jp/windows/win32/api/libloaderapi/nf-libloaderapi-loadlibraryw
708708
"""
709709
buf = ctypes.create_unicode_buffer(maxsize)
710-
length = _GetModuleFileNameW(handle, buf, ctypes.sizeof(buf))
711-
return buf[:length] # type: ignore
710+
length = _GetModuleFileNameW(handle, buf, maxsize)
711+
return buf.value[:length]
712712

713713

714714
################################################################

0 commit comments

Comments
 (0)