comtypes 1.4.7__zip → 1.4.9__zip
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {comtypes-1.4.7 → comtypes-1.4.9}/CHANGES.txt +39 -0
- {comtypes-1.4.7/comtypes.egg-info → comtypes-1.4.9}/PKG-INFO +6 -4
- {comtypes-1.4.7 → comtypes-1.4.9}/README.md +5 -3
- {comtypes-1.4.7 → comtypes-1.4.9}/comtypes/GUID.py +6 -5
- {comtypes-1.4.7 → comtypes-1.4.9}/comtypes/__init__.py +16 -5
- comtypes-1.4.9/comtypes/_comobject.py +507 -0
- {comtypes-1.4.7 → comtypes-1.4.9}/comtypes/_memberspec.py +81 -9
- comtypes-1.4.9/comtypes/_meta.py +95 -0
- {comtypes-1.4.7 → comtypes-1.4.9}/comtypes/_npsupport.py +2 -1
- {comtypes-1.4.7 → comtypes-1.4.9}/comtypes/_post_coinit/__init__.py +1 -0
- comtypes-1.4.9/comtypes/_post_coinit/_cominterface_meta_patcher.py +153 -0
- {comtypes-1.4.7 → comtypes-1.4.9}/comtypes/_post_coinit/misc.py +21 -40
- {comtypes-1.4.7 → comtypes-1.4.9}/comtypes/_post_coinit/unknwn.py +88 -209
- {comtypes-1.4.7 → comtypes-1.4.9}/comtypes/_safearray.py +1 -2
- comtypes-1.4.9/comtypes/_vtbl.py +448 -0
- {comtypes-1.4.7 → comtypes-1.4.9}/comtypes/automation.py +36 -45
- {comtypes-1.4.7 → comtypes-1.4.9}/comtypes/client/__init__.py +21 -31
- {comtypes-1.4.7 → comtypes-1.4.9}/comtypes/client/_code_cache.py +5 -4
- {comtypes-1.4.7 → comtypes-1.4.9}/comtypes/client/_constants.py +1 -1
- {comtypes-1.4.7 → comtypes-1.4.9}/comtypes/client/_events.py +1 -2
- {comtypes-1.4.7 → comtypes-1.4.9}/comtypes/client/_generate.py +9 -13
- {comtypes-1.4.7 → comtypes-1.4.9}/comtypes/client/lazybind.py +2 -7
- {comtypes-1.4.7 → comtypes-1.4.9}/comtypes/errorinfo.py +3 -3
- {comtypes-1.4.7 → comtypes-1.4.9}/comtypes/git.py +2 -2
- {comtypes-1.4.7 → comtypes-1.4.9}/comtypes/hints.pyi +11 -19
- {comtypes-1.4.7 → comtypes-1.4.9}/comtypes/persist.py +7 -7
- {comtypes-1.4.7 → comtypes-1.4.9}/comtypes/safearray.py +12 -6
- comtypes-1.4.9/comtypes/server/__init__.py +86 -0
- {comtypes-1.4.7 → comtypes-1.4.9}/comtypes/server/inprocserver.py +22 -17
- {comtypes-1.4.7 → comtypes-1.4.9}/comtypes/server/localserver.py +28 -16
- {comtypes-1.4.7 → comtypes-1.4.9}/comtypes/server/register.py +62 -73
- comtypes-1.4.9/comtypes/server/w_getopt.py +48 -0
- {comtypes-1.4.7 → comtypes-1.4.9}/comtypes/shelllink.py +49 -67
- {comtypes-1.4.7 → comtypes-1.4.9}/comtypes/test/TestComServer.py +1 -1
- {comtypes-1.4.7 → comtypes-1.4.9}/comtypes/test/TestDispServer.py +1 -1
- {comtypes-1.4.7 → comtypes-1.4.9}/comtypes/test/__init__.py +9 -12
- {comtypes-1.4.7 → comtypes-1.4.9}/comtypes/test/find_memleak.py +0 -1
- {comtypes-1.4.7 → comtypes-1.4.9}/comtypes/test/test_BSTR.py +4 -7
- {comtypes-1.4.7 → comtypes-1.4.9}/comtypes/test/test_agilent.py +0 -1
- {comtypes-1.4.7 → comtypes-1.4.9}/comtypes/test/test_avmc.py +1 -1
- {comtypes-1.4.7 → comtypes-1.4.9}/comtypes/test/test_casesensitivity.py +3 -5
- {comtypes-1.4.7 → comtypes-1.4.9}/comtypes/test/test_clear_cache.py +1 -0
- {comtypes-1.4.7 → comtypes-1.4.9}/comtypes/test/test_collections.py +3 -3
- comtypes-1.4.9/comtypes/test/test_comobject.py +146 -0
- comtypes-1.4.9/comtypes/test/test_comserver.py +319 -0
- {comtypes-1.4.7 → comtypes-1.4.9}/comtypes/test/test_createwrappers.py +2 -6
- comtypes-1.4.9/comtypes/test/test_dispinterface.py +153 -0
- {comtypes-1.4.7 → comtypes-1.4.9}/comtypes/test/test_excel.py +22 -13
- {comtypes-1.4.7 → comtypes-1.4.9}/comtypes/test/test_ie.py +2 -5
- {comtypes-1.4.7 → comtypes-1.4.9}/comtypes/test/test_inout_args.py +8 -5
- {comtypes-1.4.7 → comtypes-1.4.9}/comtypes/test/test_midl_safearray_create.py +9 -1
- {comtypes-1.4.7 → comtypes-1.4.9}/comtypes/test/test_outparam.py +17 -10
- {comtypes-1.4.7 → comtypes-1.4.9}/comtypes/test/test_safearray.py +1 -90
- comtypes-1.4.9/comtypes/test/test_server.py +350 -0
- comtypes-1.4.9/comtypes/test/test_server_register.py +536 -0
- {comtypes-1.4.7 → comtypes-1.4.9}/comtypes/test/test_shelllink.py +10 -14
- {comtypes-1.4.7 → comtypes-1.4.9}/comtypes/test/test_showevents.py +7 -17
- comtypes-1.4.9/comtypes/test/test_stream.py +131 -0
- {comtypes-1.4.7 → comtypes-1.4.9}/comtypes/test/test_typeannotator.py +1 -1
- {comtypes-1.4.7 → comtypes-1.4.9}/comtypes/test/test_urlhistory.py +1 -0
- {comtypes-1.4.7 → comtypes-1.4.9}/comtypes/test/test_variant.py +0 -19
- comtypes-1.4.9/comtypes/test/test_w_getopt.py +29 -0
- {comtypes-1.4.7 → comtypes-1.4.9}/comtypes/test/test_win32com_interop.py +80 -36
- {comtypes-1.4.7 → comtypes-1.4.9}/comtypes/test/test_wmi.py +0 -3
- {comtypes-1.4.7 → comtypes-1.4.9}/comtypes/tools/codegenerator/codegenerator.py +62 -68
- {comtypes-1.4.7 → comtypes-1.4.9}/comtypes/tools/codegenerator/helpers.py +8 -8
- {comtypes-1.4.7 → comtypes-1.4.9}/comtypes/tools/codegenerator/namespaces.py +97 -27
- {comtypes-1.4.7 → comtypes-1.4.9}/comtypes/tools/codegenerator/packing.py +4 -4
- {comtypes-1.4.7 → comtypes-1.4.9}/comtypes/tools/codegenerator/typeannotator.py +9 -11
- {comtypes-1.4.7 → comtypes-1.4.9}/comtypes/tools/tlbparser.py +33 -32
- {comtypes-1.4.7 → comtypes-1.4.9}/comtypes/tools/typedesc.py +3 -8
- {comtypes-1.4.7 → comtypes-1.4.9}/comtypes/typeinfo.py +32 -47
- {comtypes-1.4.7 → comtypes-1.4.9}/comtypes/util.py +1 -0
- {comtypes-1.4.7 → comtypes-1.4.9}/comtypes/viewobject.py +1 -5
- {comtypes-1.4.7 → comtypes-1.4.9/comtypes.egg-info}/PKG-INFO +6 -4
- {comtypes-1.4.7 → comtypes-1.4.9}/comtypes.egg-info/SOURCES.txt +6 -3
- comtypes-1.4.9/pyproject.toml +55 -0
- comtypes-1.4.7/comtypes/_comobject.py +0 -834
- comtypes-1.4.7/comtypes/_idl_stuff.py +0 -67
- comtypes-1.4.7/comtypes/_meta.py +0 -70
- comtypes-1.4.7/comtypes/server/__init__.py +0 -69
- comtypes-1.4.7/comtypes/server/w_getopt.py +0 -75
- comtypes-1.4.7/comtypes/test/test_comserver.py +0 -239
- comtypes-1.4.7/comtypes/test/test_dispinterface.py +0 -138
- comtypes-1.4.7/comtypes/test/test_propputref.py +0 -40
- comtypes-1.4.7/comtypes/test/test_server.py +0 -348
- comtypes-1.4.7/comtypes/test/test_stream.py +0 -53
- comtypes-1.4.7/pyproject.toml +0 -3
- {comtypes-1.4.7 → comtypes-1.4.9}/LICENSE.txt +0 -0
- {comtypes-1.4.7 → comtypes-1.4.9}/MANIFEST.in +0 -0
- {comtypes-1.4.7 → comtypes-1.4.9}/comtypes/_post_coinit/bstr.py +0 -0
- /comtypes-1.4.7/comtypes/_py_instance_method.py → /comtypes-1.4.9/comtypes/_post_coinit/instancemethod.py +0 -0
- {comtypes-1.4.7 → comtypes-1.4.9}/comtypes/_tlib_version_checker.py +0 -0
- {comtypes-1.4.7 → comtypes-1.4.9}/comtypes/clear_cache.py +0 -0
- {comtypes-1.4.7 → comtypes-1.4.9}/comtypes/client/dynamic.py +0 -0
- {comtypes-1.4.7 → comtypes-1.4.9}/comtypes/connectionpoints.py +0 -0
- {comtypes-1.4.7 → comtypes-1.4.9}/comtypes/hresult.py +0 -0
- {comtypes-1.4.7 → comtypes-1.4.9}/comtypes/logutil.py +0 -0
- {comtypes-1.4.7 → comtypes-1.4.9}/comtypes/messageloop.py +0 -0
- {comtypes-1.4.7 → comtypes-1.4.9}/comtypes/patcher.py +0 -0
- {comtypes-1.4.7 → comtypes-1.4.9}/comtypes/server/automation.py +0 -0
- {comtypes-1.4.7 → comtypes-1.4.9}/comtypes/server/connectionpoints.py +0 -0
- {comtypes-1.4.7 → comtypes-1.4.9}/comtypes/stream.py +0 -0
- {comtypes-1.4.7 → comtypes-1.4.9}/comtypes/test/TestComServer.idl +0 -0
- {comtypes-1.4.7 → comtypes-1.4.9}/comtypes/test/TestComServer.tlb +0 -0
- {comtypes-1.4.7 → comtypes-1.4.9}/comtypes/test/TestDispServer.idl +0 -0
- {comtypes-1.4.7 → comtypes-1.4.9}/comtypes/test/TestDispServer.tlb +0 -0
- {comtypes-1.4.7 → comtypes-1.4.9}/comtypes/test/mylib.idl +0 -0
- {comtypes-1.4.7 → comtypes-1.4.9}/comtypes/test/mylib.tlb +0 -0
- {comtypes-1.4.7 → comtypes-1.4.9}/comtypes/test/mytypelib.idl +0 -0
- {comtypes-1.4.7 → comtypes-1.4.9}/comtypes/test/runtests.py +0 -0
- {comtypes-1.4.7 → comtypes-1.4.9}/comtypes/test/setup.py +0 -0
- {comtypes-1.4.7 → comtypes-1.4.9}/comtypes/test/test_DISPPARAMS.py +0 -0
- {comtypes-1.4.7 → comtypes-1.4.9}/comtypes/test/test_GUID.py +0 -0
- {comtypes-1.4.7 → comtypes-1.4.9}/comtypes/test/test_QueryService.py +0 -0
- {comtypes-1.4.7 → comtypes-1.4.9}/comtypes/test/test_basic.py +0 -0
- {comtypes-1.4.7 → comtypes-1.4.9}/comtypes/test/test_client.py +0 -0
- {comtypes-1.4.7 → comtypes-1.4.9}/comtypes/test/test_client_dynamic.py +0 -0
- {comtypes-1.4.7 → comtypes-1.4.9}/comtypes/test/test_client_regenerate_modules.py +0 -0
- {comtypes-1.4.7 → comtypes-1.4.9}/comtypes/test/test_dict.py +0 -0
- {comtypes-1.4.7 → comtypes-1.4.9}/comtypes/test/test_dispifc_records.py +0 -0
- {comtypes-1.4.7 → comtypes-1.4.9}/comtypes/test/test_dispifc_safearrays.py +0 -0
- {comtypes-1.4.7 → comtypes-1.4.9}/comtypes/test/test_dyndispatch.py +0 -0
- {comtypes-1.4.7 → comtypes-1.4.9}/comtypes/test/test_findgendir.py +0 -0
- {comtypes-1.4.7 → comtypes-1.4.9}/comtypes/test/test_getactiveobj.py +0 -0
- {comtypes-1.4.7 → comtypes-1.4.9}/comtypes/test/test_ienum.py +0 -0
- {comtypes-1.4.7 → comtypes-1.4.9}/comtypes/test/test_imfattributes.py +0 -0
- {comtypes-1.4.7 → comtypes-1.4.9}/comtypes/test/test_jscript.js +0 -0
- {comtypes-1.4.7 → comtypes-1.4.9}/comtypes/test/test_monikers.py +0 -0
- {comtypes-1.4.7 → comtypes-1.4.9}/comtypes/test/test_msscript.py +0 -0
- {comtypes-1.4.7 → comtypes-1.4.9}/comtypes/test/test_npsupport.py +0 -0
- {comtypes-1.4.7 → comtypes-1.4.9}/comtypes/test/test_persist.py +0 -0
- {comtypes-1.4.7 → comtypes-1.4.9}/comtypes/test/test_pump_events.py +0 -0
- {comtypes-1.4.7 → comtypes-1.4.9}/comtypes/test/test_recordinfo.py +0 -0
- {comtypes-1.4.7 → comtypes-1.4.9}/comtypes/test/test_sapi.py +0 -0
- {comtypes-1.4.7 → comtypes-1.4.9}/comtypes/test/test_storage.py +0 -0
- {comtypes-1.4.7 → comtypes-1.4.9}/comtypes/test/test_subinterface.py +0 -0
- {comtypes-1.4.7 → comtypes-1.4.9}/comtypes/test/test_typeinfo.py +0 -0
- {comtypes-1.4.7 → comtypes-1.4.9}/comtypes/test/test_word.py +0 -0
- {comtypes-1.4.7 → comtypes-1.4.9}/comtypes/test/urlhist.tlb +0 -0
- {comtypes-1.4.7 → comtypes-1.4.9}/comtypes/tools/__init__.py +0 -0
- {comtypes-1.4.7 → comtypes-1.4.9}/comtypes/tools/codegenerator/__init__.py +0 -0
- {comtypes-1.4.7 → comtypes-1.4.9}/comtypes/tools/codegenerator/modulenamer.py +0 -0
- {comtypes-1.4.7 → comtypes-1.4.9}/comtypes/tools/typedesc_base.py +0 -0
- {comtypes-1.4.7 → comtypes-1.4.9}/comtypes.egg-info/dependency_links.txt +0 -0
- {comtypes-1.4.7 → comtypes-1.4.9}/comtypes.egg-info/entry_points.txt +0 -0
- {comtypes-1.4.7 → comtypes-1.4.9}/comtypes.egg-info/top_level.txt +0 -0
- {comtypes-1.4.7 → comtypes-1.4.9}/setup.cfg +0 -0
- {comtypes-1.4.7 → comtypes-1.4.9}/setup.py +0 -0
|
@@ -138,22 +138,17 @@ wrap = GetBestInterface
|
|
|
138
138
|
# Should we do this for POINTER(IUnknown) also?
|
|
139
139
|
ctypes.POINTER(automation.IDispatch).__ctypes_from_outparam__ = wrap_outparam # type: ignore
|
|
140
140
|
|
|
141
|
+
|
|
141
142
|
################################################################
|
|
142
143
|
#
|
|
143
144
|
# Object creation
|
|
144
145
|
#
|
|
145
146
|
@overload
|
|
146
|
-
def GetActiveObject(progid: _UnionT[str, CoClass, GUID]) -> Any:
|
|
147
|
-
...
|
|
148
|
-
|
|
149
|
-
|
|
147
|
+
def GetActiveObject(progid: _UnionT[str, CoClass, GUID]) -> Any: ...
|
|
150
148
|
@overload
|
|
151
149
|
def GetActiveObject(
|
|
152
150
|
progid: _UnionT[str, CoClass, GUID], interface: Type[_T_IUnknown]
|
|
153
|
-
) -> _T_IUnknown:
|
|
154
|
-
...
|
|
155
|
-
|
|
156
|
-
|
|
151
|
+
) -> _T_IUnknown: ...
|
|
157
152
|
def GetActiveObject(
|
|
158
153
|
progid: _UnionT[str, CoClass, GUID],
|
|
159
154
|
interface: Optional[Type[IUnknown]] = None,
|
|
@@ -193,14 +188,19 @@ def _manage(
|
|
|
193
188
|
if TYPE_CHECKING:
|
|
194
189
|
|
|
195
190
|
@overload
|
|
196
|
-
def GetClassObject(
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
191
|
+
def GetClassObject(
|
|
192
|
+
progid: _UnionT[str, CoClass, GUID],
|
|
193
|
+
clsctx: Optional[int] = None,
|
|
194
|
+
pServerInfo: Optional[comtypes.COSERVERINFO] = None,
|
|
195
|
+
interface: None = None,
|
|
196
|
+
) -> hints.IClassFactory: ...
|
|
200
197
|
@overload
|
|
201
|
-
def GetClassObject(
|
|
202
|
-
|
|
203
|
-
|
|
198
|
+
def GetClassObject(
|
|
199
|
+
progid: _UnionT[str, CoClass, GUID],
|
|
200
|
+
clsctx: Optional[int] = None,
|
|
201
|
+
pServerInfo: Optional[comtypes.COSERVERINFO] = None,
|
|
202
|
+
interface: Type[_T_IUnknown] = hints.IClassFactory,
|
|
203
|
+
) -> _T_IUnknown: ...
|
|
204
204
|
|
|
205
205
|
|
|
206
206
|
def GetClassObject(progid, clsctx=None, pServerInfo=None, interface=None):
|
|
@@ -216,10 +216,7 @@ def GetClassObject(progid, clsctx=None, pServerInfo=None, interface=None):
|
|
|
216
216
|
|
|
217
217
|
|
|
218
218
|
@overload
|
|
219
|
-
def CreateObject(progid: _UnionT[str, Type[CoClass], GUID]) -> Any:
|
|
220
|
-
...
|
|
221
|
-
|
|
222
|
-
|
|
219
|
+
def CreateObject(progid: _UnionT[str, Type[CoClass], GUID]) -> Any: ...
|
|
223
220
|
@overload
|
|
224
221
|
def CreateObject(
|
|
225
222
|
progid: _UnionT[str, Type[CoClass], GUID],
|
|
@@ -228,10 +225,7 @@ def CreateObject(
|
|
|
228
225
|
interface: Optional[Type[_T_IUnknown]] = None,
|
|
229
226
|
dynamic: bool = ...,
|
|
230
227
|
pServerInfo: Optional[comtypes.COSERVERINFO] = None,
|
|
231
|
-
) -> _T_IUnknown:
|
|
232
|
-
...
|
|
233
|
-
|
|
234
|
-
|
|
228
|
+
) -> _T_IUnknown: ...
|
|
235
229
|
def CreateObject(
|
|
236
230
|
progid: _UnionT[str, Type[CoClass], GUID], # which object to create
|
|
237
231
|
clsctx: Optional[int] = None, # how to create the object
|
|
@@ -297,15 +291,11 @@ def CreateObject(
|
|
|
297
291
|
|
|
298
292
|
|
|
299
293
|
@overload
|
|
300
|
-
def CoGetObject(displayname: str, interface: Type[_T_IUnknown]) -> _T_IUnknown:
|
|
301
|
-
...
|
|
302
|
-
|
|
303
|
-
|
|
294
|
+
def CoGetObject(displayname: str, interface: Type[_T_IUnknown]) -> _T_IUnknown: ...
|
|
304
295
|
@overload
|
|
305
|
-
def CoGetObject(
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
296
|
+
def CoGetObject(
|
|
297
|
+
displayname: str, interface: None = None, dynamic: bool = False
|
|
298
|
+
) -> Any: ...
|
|
309
299
|
def CoGetObject(
|
|
310
300
|
displayname: str,
|
|
311
301
|
interface: Optional[Type[comtypes.IUnknown]] = None,
|
|
@@ -4,6 +4,7 @@ The main function is _find_gen_dir(), which on-demand creates the
|
|
|
4
4
|
comtypes.gen package and returns a directory where generated code can
|
|
5
5
|
be written to.
|
|
6
6
|
"""
|
|
7
|
+
|
|
7
8
|
import ctypes, logging, os, sys, tempfile, types
|
|
8
9
|
from ctypes import wintypes
|
|
9
10
|
|
|
@@ -47,23 +48,23 @@ def _find_gen_dir():
|
|
|
47
48
|
# check type of executable image to determine a subdirectory
|
|
48
49
|
# where generated modules are placed.
|
|
49
50
|
ftype = getattr(sys, "frozen", None)
|
|
50
|
-
|
|
51
|
+
pymaj, pymin = sys.version_info[:2]
|
|
51
52
|
if ftype == None:
|
|
52
53
|
# Python script
|
|
53
|
-
subdir =
|
|
54
|
+
subdir = rf"Python\Python{pymaj:d}{pymin:d}\comtypes_cache"
|
|
54
55
|
basedir = _get_appdata_dir()
|
|
55
56
|
|
|
56
57
|
elif ftype == "dll":
|
|
57
58
|
# dll created with py2exe
|
|
58
59
|
path = _get_module_filename(sys.frozendllhandle)
|
|
59
60
|
base = os.path.splitext(os.path.basename(path))[0]
|
|
60
|
-
subdir =
|
|
61
|
+
subdir = rf"comtypes_cache\{base}-{pymaj:d}{pymin:d}"
|
|
61
62
|
basedir = tempfile.gettempdir()
|
|
62
63
|
|
|
63
64
|
else: # ftype in ('windows_exe', 'console_exe')
|
|
64
65
|
# exe created by py2exe
|
|
65
66
|
base = os.path.splitext(os.path.basename(sys.executable))[0]
|
|
66
|
-
subdir =
|
|
67
|
+
subdir = rf"comtypes_cache\{base}-{pymaj:d}{pymin:d}"
|
|
67
68
|
basedir = tempfile.gettempdir()
|
|
68
69
|
|
|
69
70
|
gen_dir = os.path.join(basedir, subdir)
|
|
@@ -118,7 +118,7 @@ class Constants(object):
|
|
|
118
118
|
# XXX is necessary warning? should use logging?
|
|
119
119
|
# import comtypes.tools
|
|
120
120
|
# if comtypes.tools.__warn_on_munge__:
|
|
121
|
-
# print("# Fixing keyword as VAR_CONST for
|
|
121
|
+
# print(f"# Fixing keyword as VAR_CONST for {name}")
|
|
122
122
|
name += "_"
|
|
123
123
|
members[name] = vdesc._.lpvarValue[0].value
|
|
124
124
|
return _frozen_attr_dict(members)
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
from __future__ import print_function
|
|
2
1
|
import ctypes
|
|
3
2
|
import traceback
|
|
4
3
|
import comtypes
|
|
@@ -228,7 +227,7 @@ class EventDumper(object):
|
|
|
228
227
|
def handler(self, this, *args, **kw):
|
|
229
228
|
# XXX handler is called with 'this'. Should we really print "None" instead?
|
|
230
229
|
args = (None,) + args
|
|
231
|
-
print("Event
|
|
230
|
+
print(f"Event {name}({', '.join([repr(a) for a in args])})")
|
|
232
231
|
|
|
233
232
|
return comtypes.instancemethod(handler, self, EventDumper)
|
|
234
233
|
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
from __future__ import print_function
|
|
2
1
|
import ctypes
|
|
3
2
|
import importlib
|
|
4
3
|
import inspect
|
|
@@ -106,7 +105,8 @@ def GetModule(tlib: _UnionT[Any, typeinfo.ITypeLib]) -> types.ModuleType:
|
|
|
106
105
|
frame = sys._getframe(1)
|
|
107
106
|
_file_: Optional[str] = frame.f_globals.get("__file__", None)
|
|
108
107
|
pathname, is_abs = _resolve_filename(
|
|
109
|
-
tlib_string,
|
|
108
|
+
tlib_string,
|
|
109
|
+
_file_ and os.path.dirname(_file_), # type: ignore
|
|
110
110
|
)
|
|
111
111
|
logger.debug("GetModule(%s), resolved: %s", pathname, is_abs)
|
|
112
112
|
tlib = _load_tlib(pathname) # don't register
|
|
@@ -139,20 +139,16 @@ def _load_tlib(obj: Any) -> typeinfo.ITypeLib:
|
|
|
139
139
|
elif isinstance(obj, GUID):
|
|
140
140
|
clsid = str(obj)
|
|
141
141
|
# lookup associated typelib in registry
|
|
142
|
-
with winreg.OpenKey(
|
|
143
|
-
winreg.HKEY_CLASSES_ROOT, r"CLSID\%s\TypeLib" % clsid
|
|
144
|
-
) as key:
|
|
142
|
+
with winreg.OpenKey(winreg.HKEY_CLASSES_ROOT, rf"CLSID\{clsid}\TypeLib") as key:
|
|
145
143
|
libid = winreg.EnumValue(key, 0)[1]
|
|
146
|
-
with winreg.OpenKey(
|
|
147
|
-
winreg.HKEY_CLASSES_ROOT, r"CLSID\%s\Version" % clsid
|
|
148
|
-
) as key:
|
|
144
|
+
with winreg.OpenKey(winreg.HKEY_CLASSES_ROOT, rf"CLSID\{clsid}\Version") as key:
|
|
149
145
|
ver = winreg.EnumValue(key, 0)[1].split(".")
|
|
150
146
|
return typeinfo.LoadRegTypeLib(GUID(libid), int(ver[0]), int(ver[1]), 0)
|
|
151
147
|
# obj is a sequence containing libid
|
|
152
148
|
elif isinstance(obj, (tuple, list)):
|
|
153
149
|
libid, ver = obj[0], obj[1:]
|
|
154
150
|
if not ver: # case of version numbers are not containing
|
|
155
|
-
with winreg.OpenKey(winreg.HKEY_CLASSES_ROOT,
|
|
151
|
+
with winreg.OpenKey(winreg.HKEY_CLASSES_ROOT, rf"TypeLib\{libid}") as key:
|
|
156
152
|
ver = [int(v, base=16) for v in winreg.EnumKey(key, 0).split(".")]
|
|
157
153
|
return typeinfo.LoadRegTypeLib(GUID(libid), *ver)
|
|
158
154
|
# obj is a COMObject implementation
|
|
@@ -161,7 +157,7 @@ def _load_tlib(obj: Any) -> typeinfo.ITypeLib:
|
|
|
161
157
|
# obj is a pointer of ITypeLib
|
|
162
158
|
elif isinstance(obj, ctypes.POINTER(typeinfo.ITypeLib)):
|
|
163
159
|
return obj # type: ignore
|
|
164
|
-
raise TypeError("'
|
|
160
|
+
raise TypeError(f"'{obj!r}' is not supported type for loading typelib")
|
|
165
161
|
|
|
166
162
|
|
|
167
163
|
def _get_existing_module(tlib: typeinfo.ITypeLib) -> Optional[types.ModuleType]:
|
|
@@ -251,9 +247,9 @@ _ItfName = str
|
|
|
251
247
|
_ItfIid = str
|
|
252
248
|
|
|
253
249
|
|
|
254
|
-
def _get_known_namespaces() ->
|
|
255
|
-
Mapping[_SymbolName, _ModuleName], Mapping[_ItfName, _ItfIid]
|
|
256
|
-
|
|
250
|
+
def _get_known_namespaces() -> (
|
|
251
|
+
Tuple[Mapping[_SymbolName, _ModuleName], Mapping[_ItfName, _ItfIid]]
|
|
252
|
+
):
|
|
257
253
|
"""Returns symbols and interfaces that are already statically defined in `ctypes`
|
|
258
254
|
and `comtypes`.
|
|
259
255
|
From `ctypes`, all the names are obtained.
|
|
@@ -67,7 +67,7 @@ class NamedProperty(object):
|
|
|
67
67
|
|
|
68
68
|
def __iter__(self):
|
|
69
69
|
"""Explicitly disallow iteration."""
|
|
70
|
-
msg = "
|
|
70
|
+
msg = f"{self.disp!r} is not iterable"
|
|
71
71
|
raise TypeError(msg)
|
|
72
72
|
|
|
73
73
|
|
|
@@ -126,11 +126,6 @@ class Dispatch(object):
|
|
|
126
126
|
"QueryInterface is forwarded to the real com object."
|
|
127
127
|
return self._comobj.QueryInterface(*args)
|
|
128
128
|
|
|
129
|
-
def __cmp__(self, other):
|
|
130
|
-
if not isinstance(other, Dispatch):
|
|
131
|
-
return 1
|
|
132
|
-
return cmp(self._comobj, other._comobj)
|
|
133
|
-
|
|
134
129
|
def __eq__(self, other):
|
|
135
130
|
return isinstance(other, Dispatch) and self._comobj == other._comobj
|
|
136
131
|
|
|
@@ -156,7 +151,7 @@ class Dispatch(object):
|
|
|
156
151
|
if descr.cParams == 1:
|
|
157
152
|
return self._comobj._invoke(descr.memid, descr.invkind, 0)
|
|
158
153
|
else:
|
|
159
|
-
raise RuntimeError("funckind
|
|
154
|
+
raise RuntimeError(f"funckind {descr.funckind:d} not yet implemented")
|
|
160
155
|
put = self.__bind(name, DISPATCH_PROPERTYPUT)
|
|
161
156
|
putref = self.__bind(name, DISPATCH_PROPERTYPUTREF)
|
|
162
157
|
return NamedProperty(self, descr, put, putref)
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import sys
|
|
2
2
|
from ctypes import *
|
|
3
|
+
from ctypes.wintypes import DWORD
|
|
3
4
|
from comtypes import IUnknown, HRESULT, COMMETHOD, GUID, BSTR
|
|
4
5
|
from comtypes.hresult import *
|
|
5
6
|
|
|
6
7
|
LPCOLESTR = c_wchar_p
|
|
7
|
-
DWORD = c_ulong
|
|
8
8
|
|
|
9
9
|
|
|
10
10
|
class ICreateErrorInfo(IUnknown):
|
|
@@ -103,9 +103,9 @@ def ReportException(
|
|
|
103
103
|
tb = tb.tb_next
|
|
104
104
|
line = tb.tb_frame.f_lineno
|
|
105
105
|
name = tb.tb_frame.f_globals["__name__"]
|
|
106
|
-
text = "
|
|
106
|
+
text = f"{typ}: {value} ({name}, line {line:d})"
|
|
107
107
|
else:
|
|
108
|
-
text = "
|
|
108
|
+
text = f"{typ}: {value}"
|
|
109
109
|
return ReportError(
|
|
110
110
|
text,
|
|
111
111
|
iid,
|
|
@@ -3,7 +3,9 @@
|
|
|
3
3
|
The global interface table provides a way to marshal interface pointers
|
|
4
4
|
between different threading appartments.
|
|
5
5
|
"""
|
|
6
|
+
|
|
6
7
|
from ctypes import *
|
|
8
|
+
from ctypes.wintypes import DWORD
|
|
7
9
|
from comtypes import (
|
|
8
10
|
IUnknown,
|
|
9
11
|
STDMETHOD,
|
|
@@ -14,8 +16,6 @@ from comtypes import (
|
|
|
14
16
|
CLSCTX_INPROC_SERVER,
|
|
15
17
|
)
|
|
16
18
|
|
|
17
|
-
DWORD = c_ulong
|
|
18
|
-
|
|
19
19
|
|
|
20
20
|
class IGlobalInterfaceTable(IUnknown):
|
|
21
21
|
_iid_ = GUID("{00000146-0000-0000-C000-000000000046}")
|
|
@@ -3,17 +3,11 @@
|
|
|
3
3
|
# - utilities for type hints.
|
|
4
4
|
import ctypes
|
|
5
5
|
import sys
|
|
6
|
-
from typing import Any as Any, ClassVar, Generic, NoReturn, TypeVar, overload
|
|
6
|
+
from typing import Any as Any, ClassVar, Generic, NoReturn, Protocol, TypeVar, overload
|
|
7
7
|
from typing import Optional, Union as _UnionT
|
|
8
|
-
from typing import
|
|
8
|
+
from typing import Tuple as Tuple, Type
|
|
9
9
|
from typing import Callable, Iterator, Sequence
|
|
10
10
|
|
|
11
|
-
if sys.version_info >= (3, 8):
|
|
12
|
-
from typing import Protocol
|
|
13
|
-
from typing import Literal as Literal
|
|
14
|
-
else:
|
|
15
|
-
from typing_extensions import Protocol
|
|
16
|
-
from typing_extensions import Literal as Literal
|
|
17
11
|
if sys.version_info >= (3, 9):
|
|
18
12
|
from typing import Annotated as Annotated
|
|
19
13
|
else:
|
|
@@ -30,10 +24,11 @@ else:
|
|
|
30
24
|
from typing_extensions import Self as Self
|
|
31
25
|
|
|
32
26
|
import comtypes
|
|
33
|
-
from comtypes import IUnknown as IUnknown, GUID as GUID
|
|
27
|
+
from comtypes import IUnknown as IUnknown, COMObject as COMObject, GUID as GUID
|
|
34
28
|
from comtypes.automation import IDispatch as IDispatch, VARIANT as VARIANT
|
|
35
29
|
from comtypes.server import IClassFactory as IClassFactory
|
|
36
|
-
from comtypes.
|
|
30
|
+
from comtypes.server import localserver as localserver
|
|
31
|
+
from comtypes.typeinfo import ITypeInfo as ITypeInfo, ITypeLib as ITypeLib
|
|
37
32
|
from comtypes._safearray import tagSAFEARRAY as tagSAFEARRAY
|
|
38
33
|
|
|
39
34
|
Incomplete: TypeAlias = Any
|
|
@@ -74,6 +69,8 @@ class LP_SAFEARRAY(ctypes._Pointer[tagSAFEARRAY], Generic[_CT]):
|
|
|
74
69
|
def unpack(self: LP_SAFEARRAY[_T_Struct]) -> Sequence[_T_Struct]: ...
|
|
75
70
|
@overload
|
|
76
71
|
def unpack(self) -> Sequence[Any]: ...
|
|
72
|
+
@classmethod
|
|
73
|
+
def from_param(cls, value: Any, /) -> Self: ...
|
|
77
74
|
|
|
78
75
|
_T_coclass = TypeVar("_T_coclass", bound=comtypes.CoClass)
|
|
79
76
|
|
|
@@ -85,11 +82,6 @@ class FirstComItfOf(Generic[_T_coclass]):
|
|
|
85
82
|
as an argument.
|
|
86
83
|
"""
|
|
87
84
|
|
|
88
|
-
class _MethodTypeDesc(Protocol):
|
|
89
|
-
arguments: List[Tuple[Any, str, List[str], Optional[Any]]]
|
|
90
|
-
idlflags: List[str]
|
|
91
|
-
name: str
|
|
92
|
-
|
|
93
85
|
_P_Put = ParamSpec("_P_Put")
|
|
94
86
|
_R_Put = TypeVar("_R_Put")
|
|
95
87
|
_P_PutRef = ParamSpec("_P_PutRef")
|
|
@@ -253,7 +245,7 @@ _T_E = TypeVar("_T_E")
|
|
|
253
245
|
def to_dunder_iter(
|
|
254
246
|
newenum: _UnionT[
|
|
255
247
|
_Descriptor[_T_Inst, Iterator[_T_E]], Callable[[_T_Inst], Iterator[_T_E]]
|
|
256
|
-
]
|
|
248
|
+
],
|
|
257
249
|
) -> Callable[[_T_Inst], Iterator[_T_E]]: ...
|
|
258
250
|
@overload
|
|
259
251
|
def to_dunder_iter(newenum: Any) -> Callable[..., NoReturn]: ...
|
|
@@ -266,7 +258,7 @@ def to_dunder_call(
|
|
|
266
258
|
_GetSetNamedProperty[_T_Inst, _P_Get, _R_Get, ...],
|
|
267
259
|
_GetOnlyNamedProperty[_T_Inst, _P_Get, _R_Get],
|
|
268
260
|
Callable[Concatenate[_T_Inst, _P_Get], _R_Get],
|
|
269
|
-
]
|
|
261
|
+
],
|
|
270
262
|
) -> Callable[Concatenate[_T_Inst, _P_Get], _R_Get]: ...
|
|
271
263
|
@overload
|
|
272
264
|
def to_dunder_call(item: Any) -> Callable[..., NoReturn]: ...
|
|
@@ -278,7 +270,7 @@ def to_dunder_getitem(
|
|
|
278
270
|
_GetSetNamedProperty[_T_Inst, _P_Get, _R_Get, ...],
|
|
279
271
|
_GetOnlyNamedProperty[_T_Inst, _P_Get, _R_Get],
|
|
280
272
|
Callable[Concatenate[_T_Inst, _P_Get], _R_Get],
|
|
281
|
-
]
|
|
273
|
+
],
|
|
282
274
|
) -> Callable[Concatenate[_T_Inst, _P_Get], _R_Get]: ...
|
|
283
275
|
@overload
|
|
284
276
|
def to_dunder_getitem(item: Any) -> Callable[..., NoReturn]: ...
|
|
@@ -289,7 +281,7 @@ def to_dunder_setitem(
|
|
|
289
281
|
item: _UnionT[
|
|
290
282
|
_GetSetNamedProperty[_T_Inst, ..., Any, _P_Set],
|
|
291
283
|
_SetOnlyNamedProperty[_T_Inst, _P_Set],
|
|
292
|
-
]
|
|
284
|
+
],
|
|
293
285
|
) -> Callable[Concatenate[_T_Inst, _P_Set], Any]: ...
|
|
294
286
|
@overload
|
|
295
287
|
def to_dunder_setitem(item: Any) -> Callable[..., NoReturn]: ...
|
|
@@ -9,6 +9,7 @@
|
|
|
9
9
|
The 'DictPropertyBag' class is a class implementing the IPropertyBag
|
|
10
10
|
interface, useful in client code.
|
|
11
11
|
"""
|
|
12
|
+
|
|
12
13
|
from ctypes import c_int, c_ulong, c_ushort, c_wchar_p
|
|
13
14
|
from ctypes import POINTER, Structure
|
|
14
15
|
from ctypes.wintypes import WORD, DWORD, BOOL
|
|
@@ -244,13 +245,12 @@ class IPersistFile(IPersist):
|
|
|
244
245
|
]
|
|
245
246
|
|
|
246
247
|
if TYPE_CHECKING:
|
|
247
|
-
|
|
248
|
-
def IsDirty(self) -> hints.Hresult: ...
|
|
249
|
-
def Load(self, pszFileName: str, dwMode: int) -> hints.Hresult: ...
|
|
250
|
-
def Save(self, pszFileName: str, fRemember: bool) -> hints.Hresult: ...
|
|
251
|
-
def SaveCompleted(self, pszFileName: str) -> hints.Hresult: ...
|
|
252
|
-
def GetCurFile(self) -> str: ...
|
|
253
|
-
# fmt: on
|
|
248
|
+
|
|
249
|
+
def IsDirty(self) -> hints.Hresult: ...
|
|
250
|
+
def Load(self, pszFileName: str, dwMode: int) -> hints.Hresult: ...
|
|
251
|
+
def Save(self, pszFileName: str, fRemember: bool) -> hints.Hresult: ...
|
|
252
|
+
def SaveCompleted(self, pszFileName: str) -> hints.Hresult: ...
|
|
253
|
+
def GetCurFile(self) -> str: ...
|
|
254
254
|
|
|
255
255
|
|
|
256
256
|
from comtypes import COMObject
|
|
@@ -78,12 +78,11 @@ def _make_safearray_type(itemtype):
|
|
|
78
78
|
VT_UNKNOWN,
|
|
79
79
|
IDispatch,
|
|
80
80
|
VT_DISPATCH,
|
|
81
|
+
VT_HRESULT,
|
|
81
82
|
)
|
|
82
83
|
|
|
83
84
|
meta = type(_safearray.tagSAFEARRAY)
|
|
84
|
-
sa_type = meta.
|
|
85
|
-
meta, "SAFEARRAY_%s" % itemtype.__name__, (_safearray.tagSAFEARRAY,), {}
|
|
86
|
-
)
|
|
85
|
+
sa_type = meta(f"SAFEARRAY_{itemtype.__name__}", (_safearray.tagSAFEARRAY,), {})
|
|
87
86
|
|
|
88
87
|
try:
|
|
89
88
|
vartype = _ctype_to_vartype[itemtype]
|
|
@@ -125,6 +124,15 @@ def _make_safearray_type(itemtype):
|
|
|
125
124
|
one-dimensional arrays. To create multidimensional arrys,
|
|
126
125
|
numpy arrays must be passed.
|
|
127
126
|
"""
|
|
127
|
+
if cls._vartype_ == VT_HRESULT:
|
|
128
|
+
raise TypeError(
|
|
129
|
+
# There are COM type libraries that define the
|
|
130
|
+
# `_midlSAFEARRAY(HRESULT)` type; however, creating `HRESULT`
|
|
131
|
+
# safearray pointer instance does not work.
|
|
132
|
+
# See also: https://github.com/enthought/comtypes/issues/668
|
|
133
|
+
"Cannot create SAFEARRAY type VT_HRESULT."
|
|
134
|
+
)
|
|
135
|
+
|
|
128
136
|
if comtypes.npsupport.isndarray(value):
|
|
129
137
|
return cls.create_from_ndarray(value, extra)
|
|
130
138
|
|
|
@@ -192,9 +200,7 @@ def _make_safearray_type(itemtype):
|
|
|
192
200
|
nitems *= d
|
|
193
201
|
rgsa[i].cElements = d
|
|
194
202
|
rgsa[i].lBound = lBound
|
|
195
|
-
pa = _safearray.SafeArrayCreateEx(
|
|
196
|
-
cls._vartype_, value.ndim, rgsa, extra # cDims # rgsaBound
|
|
197
|
-
) # pvExtra
|
|
203
|
+
pa = _safearray.SafeArrayCreateEx(cls._vartype_, value.ndim, rgsa, extra)
|
|
198
204
|
if not pa:
|
|
199
205
|
if cls._vartype_ == VT_RECORD and extra is None:
|
|
200
206
|
raise TypeError(
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import ctypes
|
|
2
|
+
from ctypes import HRESULT, POINTER, byref
|
|
3
|
+
from typing import TYPE_CHECKING, Any, Optional, Type
|
|
4
|
+
|
|
5
|
+
import comtypes
|
|
6
|
+
import comtypes.client
|
|
7
|
+
import comtypes.client.dynamic
|
|
8
|
+
from comtypes import GUID, STDMETHOD, IUnknown
|
|
9
|
+
from comtypes.automation import IDispatch
|
|
10
|
+
|
|
11
|
+
if TYPE_CHECKING:
|
|
12
|
+
from ctypes import _Pointer
|
|
13
|
+
|
|
14
|
+
from comtypes import hints # type: ignore
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
################################################################
|
|
18
|
+
# Interfaces
|
|
19
|
+
class IClassFactory(IUnknown):
|
|
20
|
+
_iid_ = GUID("{00000001-0000-0000-C000-000000000046}")
|
|
21
|
+
_methods_ = [
|
|
22
|
+
STDMETHOD(
|
|
23
|
+
HRESULT,
|
|
24
|
+
"CreateInstance",
|
|
25
|
+
[POINTER(IUnknown), POINTER(GUID), POINTER(ctypes.c_void_p)],
|
|
26
|
+
),
|
|
27
|
+
STDMETHOD(HRESULT, "LockServer", [ctypes.c_int]),
|
|
28
|
+
]
|
|
29
|
+
|
|
30
|
+
def CreateInstance(
|
|
31
|
+
self,
|
|
32
|
+
punkouter: Optional[Type["_Pointer[IUnknown]"]] = None,
|
|
33
|
+
interface: Optional[Type[IUnknown]] = None,
|
|
34
|
+
dynamic: bool = False,
|
|
35
|
+
) -> Any:
|
|
36
|
+
if dynamic:
|
|
37
|
+
if interface is not None:
|
|
38
|
+
raise ValueError("interface and dynamic are mutually exclusive")
|
|
39
|
+
itf = IDispatch
|
|
40
|
+
elif interface is None:
|
|
41
|
+
itf = IUnknown
|
|
42
|
+
else:
|
|
43
|
+
itf = interface
|
|
44
|
+
obj = POINTER(itf)()
|
|
45
|
+
self.__com_CreateInstance(punkouter, itf._iid_, byref(obj)) # type: ignore
|
|
46
|
+
if dynamic:
|
|
47
|
+
return comtypes.client.dynamic.Dispatch(obj)
|
|
48
|
+
elif interface is None:
|
|
49
|
+
# An interface was not specified, so return the best.
|
|
50
|
+
return comtypes.client.GetBestInterface(obj)
|
|
51
|
+
# An interface was specified and obj is already that interface.
|
|
52
|
+
return obj
|
|
53
|
+
|
|
54
|
+
if TYPE_CHECKING:
|
|
55
|
+
|
|
56
|
+
def LockServer(self, fLock: int) -> hints.Hresult: ...
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
# class IExternalConnection(IUnknown):
|
|
60
|
+
# _iid_ = GUID("{00000019-0000-0000-C000-000000000046}")
|
|
61
|
+
# _methods_ = [
|
|
62
|
+
# STDMETHOD(HRESULT, "AddConnection", [c_ulong, c_ulong]),
|
|
63
|
+
# STDMETHOD(HRESULT, "ReleaseConnection", [c_ulong, c_ulong, c_ulong])]
|
|
64
|
+
|
|
65
|
+
# The following code is untested:
|
|
66
|
+
|
|
67
|
+
ACTIVEOBJECT_STRONG = 0x0
|
|
68
|
+
ACTIVEOBJECT_WEAK = 0x1
|
|
69
|
+
|
|
70
|
+
oleaut32 = ctypes.oledll.oleaut32
|
|
71
|
+
|
|
72
|
+
|
|
73
|
+
def RegisterActiveObject(comobj: comtypes.COMObject, weak: bool = True) -> int:
|
|
74
|
+
punk = comobj._com_pointers_[IUnknown._iid_]
|
|
75
|
+
clsid = comobj._reg_clsid_
|
|
76
|
+
if weak:
|
|
77
|
+
flags = ACTIVEOBJECT_WEAK
|
|
78
|
+
else:
|
|
79
|
+
flags = ACTIVEOBJECT_STRONG
|
|
80
|
+
handle = ctypes.c_ulong()
|
|
81
|
+
oleaut32.RegisterActiveObject(punk, byref(clsid), flags, byref(handle))
|
|
82
|
+
return handle.value
|
|
83
|
+
|
|
84
|
+
|
|
85
|
+
def RevokeActiveObject(handle: int) -> None:
|
|
86
|
+
oleaut32.RevokeActiveObject(handle, None)
|
|
@@ -1,12 +1,11 @@
|
|
|
1
1
|
import ctypes
|
|
2
|
-
from comtypes import COMObject, GUID
|
|
3
|
-
from comtypes.server import IClassFactory
|
|
4
|
-
from comtypes.hresult import *
|
|
5
|
-
|
|
6
|
-
import sys
|
|
7
2
|
import logging
|
|
3
|
+
import sys
|
|
8
4
|
import winreg
|
|
5
|
+
from typing import Any, Literal, Optional, Type
|
|
9
6
|
|
|
7
|
+
from comtypes import GUID, COMObject, IUnknown, hresult
|
|
8
|
+
from comtypes.server import IClassFactory
|
|
10
9
|
|
|
11
10
|
logger = logging.getLogger(__name__)
|
|
12
11
|
_debug = logger.debug
|
|
@@ -18,33 +17,39 @@ _critical = logger.critical
|
|
|
18
17
|
class ClassFactory(COMObject):
|
|
19
18
|
_com_interfaces_ = [IClassFactory]
|
|
20
19
|
|
|
21
|
-
def __init__(self, cls):
|
|
20
|
+
def __init__(self, cls: Type[COMObject]) -> None:
|
|
22
21
|
super(ClassFactory, self).__init__()
|
|
23
22
|
self._cls = cls
|
|
24
23
|
|
|
25
|
-
def IClassFactory_CreateInstance(
|
|
24
|
+
def IClassFactory_CreateInstance(
|
|
25
|
+
self,
|
|
26
|
+
this: Any,
|
|
27
|
+
punkOuter: Optional[Type["ctypes._Pointer[IUnknown]"]],
|
|
28
|
+
riid: "ctypes._Pointer[GUID]",
|
|
29
|
+
ppv: ctypes.c_void_p,
|
|
30
|
+
) -> int:
|
|
26
31
|
_debug("ClassFactory.CreateInstance(%s)", riid[0])
|
|
27
32
|
result = self._cls().IUnknown_QueryInterface(None, riid, ppv)
|
|
28
33
|
_debug("CreateInstance() -> %s", result)
|
|
29
34
|
return result
|
|
30
35
|
|
|
31
|
-
def IClassFactory_LockServer(self, this, fLock):
|
|
36
|
+
def IClassFactory_LockServer(self, this: Any, fLock: bool) -> Literal[0]:
|
|
32
37
|
if fLock:
|
|
33
38
|
COMObject.__server__.Lock()
|
|
34
39
|
else:
|
|
35
40
|
COMObject.__server__.Unlock()
|
|
36
|
-
return S_OK
|
|
41
|
+
return hresult.S_OK
|
|
37
42
|
|
|
38
43
|
|
|
39
44
|
# will be set by py2exe boot script 'from outside'
|
|
40
45
|
_clsid_to_class = {}
|
|
41
46
|
|
|
42
47
|
|
|
43
|
-
def inproc_find_class(clsid):
|
|
48
|
+
def inproc_find_class(clsid: GUID) -> Type[COMObject]:
|
|
44
49
|
if _clsid_to_class:
|
|
45
50
|
return _clsid_to_class[clsid]
|
|
46
51
|
|
|
47
|
-
key = winreg.OpenKey(winreg.HKEY_CLASSES_ROOT, "CLSID
|
|
52
|
+
key = winreg.OpenKey(winreg.HKEY_CLASSES_ROOT, f"CLSID\\{clsid}\\InprocServer32")
|
|
48
53
|
try:
|
|
49
54
|
pathdir = winreg.QueryValueEx(key, "PythonPath")[0]
|
|
50
55
|
except:
|
|
@@ -70,7 +75,7 @@ def inproc_find_class(clsid):
|
|
|
70
75
|
_logging_configured = False
|
|
71
76
|
|
|
72
77
|
|
|
73
|
-
def _setup_logging(clsid):
|
|
78
|
+
def _setup_logging(clsid: GUID) -> None:
|
|
74
79
|
"""Read from the registry, and configure the logging module.
|
|
75
80
|
|
|
76
81
|
Currently, the handler (NTDebugHandler) is hardcoded.
|
|
@@ -109,7 +114,7 @@ def _setup_logging(clsid):
|
|
|
109
114
|
logging.getLogger(name).setLevel(level)
|
|
110
115
|
|
|
111
116
|
|
|
112
|
-
def DllGetClassObject(rclsid, riid, ppv):
|
|
117
|
+
def DllGetClassObject(rclsid: int, riid: int, ppv: int) -> int:
|
|
113
118
|
COMObject.__run_inprocserver__()
|
|
114
119
|
|
|
115
120
|
iid = GUID.from_address(riid)
|
|
@@ -127,7 +132,7 @@ def DllGetClassObject(rclsid, riid, ppv):
|
|
|
127
132
|
|
|
128
133
|
cls = inproc_find_class(clsid)
|
|
129
134
|
if not cls:
|
|
130
|
-
return CLASS_E_CLASSNOTAVAILABLE
|
|
135
|
+
return hresult.CLASS_E_CLASSNOTAVAILABLE
|
|
131
136
|
|
|
132
137
|
result = ClassFactory(cls).IUnknown_QueryInterface(
|
|
133
138
|
None, ctypes.pointer(iid), ctypes.c_void_p(ppv)
|
|
@@ -136,12 +141,12 @@ def DllGetClassObject(rclsid, riid, ppv):
|
|
|
136
141
|
return result
|
|
137
142
|
except Exception:
|
|
138
143
|
_critical("DllGetClassObject", exc_info=True)
|
|
139
|
-
return E_FAIL
|
|
144
|
+
return hresult.E_FAIL
|
|
140
145
|
|
|
141
146
|
|
|
142
|
-
def DllCanUnloadNow():
|
|
147
|
+
def DllCanUnloadNow() -> Literal[1]: # S_FALSE
|
|
143
148
|
COMObject.__run_inprocserver__()
|
|
144
149
|
result = COMObject.__server__.DllCanUnloadNow()
|
|
145
150
|
# To avoid a memory leak when PyInitialize()/PyUninitialize() are
|
|
146
151
|
# called several times, we refuse to unload the dll.
|
|
147
|
-
return S_FALSE
|
|
152
|
+
return hresult.S_FALSE
|