File tree 4 files changed +10
-10
lines changed
4 files changed +10
-10
lines changed Original file line number Diff line number Diff line change 50
50
from comtypes .server import w_getopt
51
51
from comtypes .typeinfo import (
52
52
REGKIND_REGISTER ,
53
+ GetModuleFileName ,
53
54
LoadTypeLibEx ,
54
55
UnRegisterTypeLib ,
55
- GetModuleFileNameW ,
56
56
)
57
57
58
58
_debug = logging .getLogger (__name__ ).debug
@@ -225,7 +225,7 @@ def _get_serverdll():
225
225
"""Return the pathname of the dll hosting the COM object."""
226
226
handle = getattr (sys , "frozendllhandle" , None )
227
227
if handle is not None :
228
- return GetModuleFileNameW (handle , 260 )
228
+ return GetModuleFileName (handle , 260 )
229
229
import _ctypes
230
230
231
231
return _ctypes .__file__
Original file line number Diff line number Diff line change @@ -193,7 +193,7 @@ class Test_get_serverdll(ut.TestCase):
193
193
def test_nonfrozen (self ):
194
194
self .assertEqual (_ctypes .__file__ , _get_serverdll ())
195
195
196
- @mock .patch .object (register , "GetModuleFileNameW " )
196
+ @mock .patch .object (register , "GetModuleFileName " )
197
197
@mock .patch .object (register , "sys" )
198
198
def test_frozen (self , _sys , GetModuleFileName ):
199
199
handle , dll_path = 1234 , r"path\to\frozendll"
Original file line number Diff line number Diff line change 6
6
from comtypes .typeinfo import (
7
7
TKIND_DISPATCH ,
8
8
TKIND_INTERFACE ,
9
- GetModuleFileNameW ,
9
+ GetModuleFileName ,
10
10
LoadRegTypeLib ,
11
11
LoadTypeLibEx ,
12
12
QueryPathOfRegTypeLib ,
@@ -94,16 +94,16 @@ def test_TypeInfo(self):
94
94
self .assertEqual (guid , ti .GetTypeAttr ().guid )
95
95
96
96
97
- class Test_GetModuleFileNameW (unittest .TestCase ):
97
+ class Test_GetModuleFileName (unittest .TestCase ):
98
98
def test_null_handler (self ):
99
- self .assertEqual (GetModuleFileNameW (None , 260 ), sys .executable )
99
+ self .assertEqual (GetModuleFileName (None , 260 ), sys .executable )
100
100
101
101
def test_loaded_module_handle (self ):
102
102
import _ctypes
103
103
104
104
dll_path = _ctypes .__file__
105
105
hmodule = ctypes .WinDLL (dll_path )._handle
106
- self .assertEqual (GetModuleFileNameW (hmodule , 260 ), dll_path )
106
+ self .assertEqual (GetModuleFileName (hmodule , 260 ), dll_path )
107
107
108
108
109
109
if __name__ == "__main__" :
Original file line number Diff line number Diff line change @@ -700,15 +700,15 @@ def QueryPathOfRegTypeLib(
700
700
_GetModuleFileNameW .restype = DWORD
701
701
702
702
703
- def GetModuleFileNameW (handle : Optional [int ], maxsize : int ) -> str :
703
+ def GetModuleFileName (handle : Optional [int ], maxsize : int ) -> str :
704
704
"""Returns the fullpath of the loaded module specified by the handle.
705
705
If the handle is NULL, returns the executable file path of the current process.
706
706
707
707
https://learn.microsoft.com/ja-jp/windows/win32/api/libloaderapi/nf-libloaderapi-loadlibraryw
708
708
"""
709
709
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 ]
712
712
713
713
714
714
################################################################
You can’t perform that action at this time.
0 commit comments