comtypes 1.4.9__zip → 1.4.10__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.9 → comtypes-1.4.10}/CHANGES.txt +19 -0
- {comtypes-1.4.9/comtypes.egg-info → comtypes-1.4.10}/PKG-INFO +3 -2
- {comtypes-1.4.9 → comtypes-1.4.10}/comtypes/GUID.py +34 -13
- {comtypes-1.4.9 → comtypes-1.4.10}/comtypes/__init__.py +22 -13
- {comtypes-1.4.9 → comtypes-1.4.10}/comtypes/_comobject.py +69 -14
- {comtypes-1.4.9 → comtypes-1.4.10}/comtypes/_memberspec.py +14 -6
- {comtypes-1.4.9 → comtypes-1.4.10}/comtypes/_meta.py +1 -0
- {comtypes-1.4.9 → comtypes-1.4.10}/comtypes/_post_coinit/_cominterface_meta_patcher.py +0 -1
- {comtypes-1.4.9 → comtypes-1.4.10}/comtypes/_post_coinit/bstr.py +12 -5
- {comtypes-1.4.9 → comtypes-1.4.10}/comtypes/_post_coinit/instancemethod.py +1 -2
- {comtypes-1.4.9 → comtypes-1.4.10}/comtypes/_post_coinit/misc.py +59 -24
- {comtypes-1.4.9 → comtypes-1.4.10}/comtypes/_post_coinit/unknwn.py +2 -6
- {comtypes-1.4.9 → comtypes-1.4.10}/comtypes/_safearray.py +2 -2
- {comtypes-1.4.9 → comtypes-1.4.10}/comtypes/automation.py +10 -4
- comtypes-1.4.10/comtypes/client/__init__.py +42 -0
- comtypes-1.4.10/comtypes/client/_activeobj.py +46 -0
- {comtypes-1.4.9 → comtypes-1.4.10}/comtypes/client/_code_cache.py +6 -1
- comtypes-1.4.10/comtypes/client/_create.py +147 -0
- {comtypes-1.4.9 → comtypes-1.4.10}/comtypes/client/_events.py +57 -12
- {comtypes-1.4.9 → comtypes-1.4.10}/comtypes/client/_generate.py +3 -3
- comtypes-1.4.10/comtypes/client/_managing.py +114 -0
- {comtypes-1.4.9 → comtypes-1.4.10}/comtypes/client/dynamic.py +2 -3
- {comtypes-1.4.9 → comtypes-1.4.10}/comtypes/client/lazybind.py +10 -11
- {comtypes-1.4.9 → comtypes-1.4.10}/comtypes/connectionpoints.py +2 -1
- {comtypes-1.4.9 → comtypes-1.4.10}/comtypes/errorinfo.py +20 -7
- {comtypes-1.4.9 → comtypes-1.4.10}/comtypes/git.py +4 -3
- {comtypes-1.4.9 → comtypes-1.4.10}/comtypes/logutil.py +15 -3
- {comtypes-1.4.9 → comtypes-1.4.10}/comtypes/messageloop.py +1 -1
- {comtypes-1.4.9 → comtypes-1.4.10}/comtypes/persist.py +3 -5
- {comtypes-1.4.9 → comtypes-1.4.10}/comtypes/safearray.py +8 -6
- {comtypes-1.4.9 → comtypes-1.4.10}/comtypes/server/__init__.py +22 -4
- {comtypes-1.4.9 → comtypes-1.4.10}/comtypes/server/automation.py +1 -2
- {comtypes-1.4.9 → comtypes-1.4.10}/comtypes/server/connectionpoints.py +5 -5
- {comtypes-1.4.9 → comtypes-1.4.10}/comtypes/server/inprocserver.py +6 -3
- {comtypes-1.4.9 → comtypes-1.4.10}/comtypes/server/localserver.py +23 -5
- comtypes-1.4.10/comtypes/server/register.py +478 -0
- {comtypes-1.4.9 → comtypes-1.4.10}/comtypes/shelllink.py +13 -7
- {comtypes-1.4.9 → comtypes-1.4.10}/comtypes/stream.py +7 -4
- {comtypes-1.4.9 → comtypes-1.4.10}/comtypes/test/TestComServer.py +6 -7
- {comtypes-1.4.9 → comtypes-1.4.10}/comtypes/test/TestDispServer.py +4 -2
- {comtypes-1.4.9 → comtypes-1.4.10}/comtypes/test/__init__.py +1 -1
- comtypes-1.4.10/comtypes/test/find_memleak.py +72 -0
- {comtypes-1.4.9 → comtypes-1.4.10}/comtypes/test/runtests.py +1 -0
- {comtypes-1.4.9 → comtypes-1.4.10}/comtypes/test/setup.py +2 -1
- {comtypes-1.4.9 → comtypes-1.4.10}/comtypes/test/test_BSTR.py +7 -17
- {comtypes-1.4.9 → comtypes-1.4.10}/comtypes/test/test_GUID.py +1 -0
- {comtypes-1.4.9 → comtypes-1.4.10}/comtypes/test/test_QueryService.py +1 -0
- {comtypes-1.4.9 → comtypes-1.4.10}/comtypes/test/test_agilent.py +4 -3
- {comtypes-1.4.9 → comtypes-1.4.10}/comtypes/test/test_basic.py +12 -6
- {comtypes-1.4.9 → comtypes-1.4.10}/comtypes/test/test_clear_cache.py +1 -1
- {comtypes-1.4.9 → comtypes-1.4.10}/comtypes/test/test_client.py +2 -2
- {comtypes-1.4.9 → comtypes-1.4.10}/comtypes/test/test_client_dynamic.py +2 -2
- {comtypes-1.4.9 → comtypes-1.4.10}/comtypes/test/test_client_regenerate_modules.py +2 -2
- {comtypes-1.4.9 → comtypes-1.4.10}/comtypes/test/test_collections.py +1 -1
- {comtypes-1.4.9 → comtypes-1.4.10}/comtypes/test/test_comobject.py +4 -4
- {comtypes-1.4.9 → comtypes-1.4.10}/comtypes/test/test_comserver.py +31 -1
- {comtypes-1.4.9 → comtypes-1.4.10}/comtypes/test/test_dispifc_records.py +1 -1
- {comtypes-1.4.9 → comtypes-1.4.10}/comtypes/test/test_dispifc_safearrays.py +1 -1
- {comtypes-1.4.9 → comtypes-1.4.10}/comtypes/test/test_dyndispatch.py +1 -0
- {comtypes-1.4.9 → comtypes-1.4.10}/comtypes/test/test_findgendir.py +1 -2
- {comtypes-1.4.9 → comtypes-1.4.10}/comtypes/test/test_getactiveobj.py +4 -4
- {comtypes-1.4.9 → comtypes-1.4.10}/comtypes/test/test_ie.py +19 -6
- {comtypes-1.4.9 → comtypes-1.4.10}/comtypes/test/test_ienum.py +2 -2
- {comtypes-1.4.9 → comtypes-1.4.10}/comtypes/test/test_imfattributes.py +13 -3
- {comtypes-1.4.9 → comtypes-1.4.10}/comtypes/test/test_inout_args.py +1 -1
- {comtypes-1.4.9 → comtypes-1.4.10}/comtypes/test/test_midl_safearray_create.py +6 -4
- {comtypes-1.4.9 → comtypes-1.4.10}/comtypes/test/test_monikers.py +23 -9
- {comtypes-1.4.9 → comtypes-1.4.10}/comtypes/test/test_msscript.py +2 -1
- {comtypes-1.4.9 → comtypes-1.4.10}/comtypes/test/test_npsupport.py +4 -4
- {comtypes-1.4.9 → comtypes-1.4.10}/comtypes/test/test_outparam.py +22 -6
- {comtypes-1.4.9 → comtypes-1.4.10}/comtypes/test/test_persist.py +2 -4
- {comtypes-1.4.9 → comtypes-1.4.10}/comtypes/test/test_recordinfo.py +1 -1
- {comtypes-1.4.9 → comtypes-1.4.10}/comtypes/test/test_sapi.py +4 -1
- {comtypes-1.4.9 → comtypes-1.4.10}/comtypes/test/test_server_register.py +113 -125
- {comtypes-1.4.9 → comtypes-1.4.10}/comtypes/test/test_shelllink.py +2 -3
- {comtypes-1.4.9 → comtypes-1.4.10}/comtypes/test/test_storage.py +12 -6
- {comtypes-1.4.9 → comtypes-1.4.10}/comtypes/test/test_stream.py +16 -5
- {comtypes-1.4.9 → comtypes-1.4.10}/comtypes/test/test_subinterface.py +4 -2
- {comtypes-1.4.9 → comtypes-1.4.10}/comtypes/test/test_typeannotator.py +1 -2
- {comtypes-1.4.9 → comtypes-1.4.10}/comtypes/test/test_typeinfo.py +19 -7
- {comtypes-1.4.9 → comtypes-1.4.10}/comtypes/test/test_urlhistory.py +7 -4
- {comtypes-1.4.9 → comtypes-1.4.10}/comtypes/test/test_variant.py +3 -2
- {comtypes-1.4.9 → comtypes-1.4.10}/comtypes/test/test_word.py +1 -1
- {comtypes-1.4.9 → comtypes-1.4.10}/comtypes/tools/codegenerator/codegenerator.py +167 -435
- comtypes-1.4.10/comtypes/tools/codegenerator/comments.py +79 -0
- comtypes-1.4.10/comtypes/tools/codegenerator/heads.py +192 -0
- {comtypes-1.4.9 → comtypes-1.4.10}/comtypes/tools/codegenerator/helpers.py +3 -6
- {comtypes-1.4.9 → comtypes-1.4.10}/comtypes/tools/codegenerator/namespaces.py +13 -5
- {comtypes-1.4.9 → comtypes-1.4.10}/comtypes/tools/codegenerator/typeannotator.py +13 -3
- {comtypes-1.4.9 → comtypes-1.4.10}/comtypes/tools/tlbparser.py +22 -23
- {comtypes-1.4.9 → comtypes-1.4.10}/comtypes/tools/typedesc.py +3 -2
- {comtypes-1.4.9 → comtypes-1.4.10}/comtypes/tools/typedesc_base.py +2 -2
- {comtypes-1.4.9 → comtypes-1.4.10}/comtypes/typeinfo.py +149 -42
- {comtypes-1.4.9 → comtypes-1.4.10}/comtypes/viewobject.py +2 -4
- {comtypes-1.4.9 → comtypes-1.4.10/comtypes.egg-info}/PKG-INFO +3 -2
- {comtypes-1.4.9 → comtypes-1.4.10}/comtypes.egg-info/SOURCES.txt +5 -0
- {comtypes-1.4.9 → comtypes-1.4.10}/pyproject.toml +11 -19
- comtypes-1.4.9/comtypes/client/__init__.py +0 -323
- comtypes-1.4.9/comtypes/server/register.py +0 -419
- comtypes-1.4.9/comtypes/test/find_memleak.py +0 -76
- {comtypes-1.4.9 → comtypes-1.4.10}/LICENSE.txt +0 -0
- {comtypes-1.4.9 → comtypes-1.4.10}/MANIFEST.in +0 -0
- {comtypes-1.4.9 → comtypes-1.4.10}/README.md +0 -0
- {comtypes-1.4.9 → comtypes-1.4.10}/comtypes/_npsupport.py +0 -0
- {comtypes-1.4.9 → comtypes-1.4.10}/comtypes/_post_coinit/__init__.py +0 -0
- {comtypes-1.4.9 → comtypes-1.4.10}/comtypes/_tlib_version_checker.py +0 -0
- {comtypes-1.4.9 → comtypes-1.4.10}/comtypes/_vtbl.py +0 -0
- {comtypes-1.4.9 → comtypes-1.4.10}/comtypes/clear_cache.py +0 -0
- {comtypes-1.4.9 → comtypes-1.4.10}/comtypes/client/_constants.py +0 -0
- {comtypes-1.4.9 → comtypes-1.4.10}/comtypes/hints.pyi +0 -0
- {comtypes-1.4.9 → comtypes-1.4.10}/comtypes/hresult.py +0 -0
- {comtypes-1.4.9 → comtypes-1.4.10}/comtypes/patcher.py +0 -0
- {comtypes-1.4.9 → comtypes-1.4.10}/comtypes/server/w_getopt.py +0 -0
- {comtypes-1.4.9 → comtypes-1.4.10}/comtypes/test/TestComServer.idl +0 -0
- {comtypes-1.4.9 → comtypes-1.4.10}/comtypes/test/TestComServer.tlb +0 -0
- {comtypes-1.4.9 → comtypes-1.4.10}/comtypes/test/TestDispServer.idl +0 -0
- {comtypes-1.4.9 → comtypes-1.4.10}/comtypes/test/TestDispServer.tlb +0 -0
- {comtypes-1.4.9 → comtypes-1.4.10}/comtypes/test/mylib.idl +0 -0
- {comtypes-1.4.9 → comtypes-1.4.10}/comtypes/test/mylib.tlb +0 -0
- {comtypes-1.4.9 → comtypes-1.4.10}/comtypes/test/mytypelib.idl +0 -0
- {comtypes-1.4.9 → comtypes-1.4.10}/comtypes/test/test_DISPPARAMS.py +0 -0
- {comtypes-1.4.9 → comtypes-1.4.10}/comtypes/test/test_avmc.py +0 -0
- {comtypes-1.4.9 → comtypes-1.4.10}/comtypes/test/test_casesensitivity.py +0 -0
- {comtypes-1.4.9 → comtypes-1.4.10}/comtypes/test/test_createwrappers.py +0 -0
- {comtypes-1.4.9 → comtypes-1.4.10}/comtypes/test/test_dict.py +0 -0
- {comtypes-1.4.9 → comtypes-1.4.10}/comtypes/test/test_dispinterface.py +0 -0
- {comtypes-1.4.9 → comtypes-1.4.10}/comtypes/test/test_excel.py +0 -0
- {comtypes-1.4.9 → comtypes-1.4.10}/comtypes/test/test_jscript.js +0 -0
- {comtypes-1.4.9 → comtypes-1.4.10}/comtypes/test/test_pump_events.py +0 -0
- {comtypes-1.4.9 → comtypes-1.4.10}/comtypes/test/test_safearray.py +0 -0
- {comtypes-1.4.9 → comtypes-1.4.10}/comtypes/test/test_server.py +0 -0
- {comtypes-1.4.9 → comtypes-1.4.10}/comtypes/test/test_showevents.py +0 -0
- {comtypes-1.4.9 → comtypes-1.4.10}/comtypes/test/test_w_getopt.py +0 -0
- {comtypes-1.4.9 → comtypes-1.4.10}/comtypes/test/test_win32com_interop.py +0 -0
- {comtypes-1.4.9 → comtypes-1.4.10}/comtypes/test/test_wmi.py +0 -0
- {comtypes-1.4.9 → comtypes-1.4.10}/comtypes/test/urlhist.tlb +0 -0
- {comtypes-1.4.9 → comtypes-1.4.10}/comtypes/tools/__init__.py +0 -0
- {comtypes-1.4.9 → comtypes-1.4.10}/comtypes/tools/codegenerator/__init__.py +0 -0
- {comtypes-1.4.9 → comtypes-1.4.10}/comtypes/tools/codegenerator/modulenamer.py +0 -0
- {comtypes-1.4.9 → comtypes-1.4.10}/comtypes/tools/codegenerator/packing.py +0 -0
- {comtypes-1.4.9 → comtypes-1.4.10}/comtypes/util.py +0 -0
- {comtypes-1.4.9 → comtypes-1.4.10}/comtypes.egg-info/dependency_links.txt +0 -0
- {comtypes-1.4.9 → comtypes-1.4.10}/comtypes.egg-info/entry_points.txt +0 -0
- {comtypes-1.4.9 → comtypes-1.4.10}/comtypes.egg-info/top_level.txt +0 -0
- {comtypes-1.4.9 → comtypes-1.4.10}/setup.cfg +0 -0
- {comtypes-1.4.9 → comtypes-1.4.10}/setup.py +0 -0
|
@@ -1,323 +0,0 @@
|
|
|
1
|
-
"""comtypes.client - High level client level COM support package."""
|
|
2
|
-
|
|
3
|
-
################################################################
|
|
4
|
-
#
|
|
5
|
-
# TODO:
|
|
6
|
-
#
|
|
7
|
-
# - refactor some code into modules
|
|
8
|
-
#
|
|
9
|
-
################################################################
|
|
10
|
-
|
|
11
|
-
import ctypes
|
|
12
|
-
import logging
|
|
13
|
-
import os
|
|
14
|
-
import sys
|
|
15
|
-
from typing import Any, overload, TypeVar, TYPE_CHECKING
|
|
16
|
-
from typing import Optional, Type, Union as _UnionT
|
|
17
|
-
|
|
18
|
-
import comtypes
|
|
19
|
-
from comtypes.hresult import *
|
|
20
|
-
from comtypes import automation, CoClass, GUID, IUnknown, typeinfo
|
|
21
|
-
import comtypes.client.dynamic
|
|
22
|
-
from comtypes.client._constants import Constants
|
|
23
|
-
from comtypes.client._events import GetEvents, ShowEvents, PumpEvents
|
|
24
|
-
from comtypes.client._generate import GetModule
|
|
25
|
-
from comtypes.client._code_cache import _find_gen_dir
|
|
26
|
-
|
|
27
|
-
if TYPE_CHECKING:
|
|
28
|
-
from comtypes import hints # type: ignore
|
|
29
|
-
|
|
30
|
-
gen_dir = _find_gen_dir()
|
|
31
|
-
import comtypes.gen
|
|
32
|
-
|
|
33
|
-
### for testing
|
|
34
|
-
##gen_dir = None
|
|
35
|
-
|
|
36
|
-
_T_IUnknown = TypeVar("_T_IUnknown", bound=IUnknown)
|
|
37
|
-
logger = logging.getLogger(__name__)
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
def wrap_outparam(punk: Any) -> Any:
|
|
41
|
-
logger.debug("wrap_outparam(%s)", punk)
|
|
42
|
-
if not punk:
|
|
43
|
-
return None
|
|
44
|
-
if punk.__com_interface__ == automation.IDispatch:
|
|
45
|
-
return GetBestInterface(punk)
|
|
46
|
-
return punk
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
def GetBestInterface(punk: Any) -> Any:
|
|
50
|
-
"""Try to QueryInterface a COM pointer to the 'most useful'
|
|
51
|
-
interface.
|
|
52
|
-
|
|
53
|
-
Get type information for the provided object, either via
|
|
54
|
-
IDispatch.GetTypeInfo(), or via IProvideClassInfo.GetClassInfo().
|
|
55
|
-
Generate a wrapper module for the typelib, and QI for the
|
|
56
|
-
interface found.
|
|
57
|
-
"""
|
|
58
|
-
if not punk: # NULL COM pointer
|
|
59
|
-
return punk # or should we return None?
|
|
60
|
-
# find the typelib and the interface name
|
|
61
|
-
logger.debug("GetBestInterface(%s)", punk)
|
|
62
|
-
try:
|
|
63
|
-
try:
|
|
64
|
-
pci = punk.QueryInterface(typeinfo.IProvideClassInfo)
|
|
65
|
-
logger.debug("Does implement IProvideClassInfo")
|
|
66
|
-
except comtypes.COMError:
|
|
67
|
-
# Some COM objects support IProvideClassInfo2, but not IProvideClassInfo.
|
|
68
|
-
# These objects are broken, but we support them anyway.
|
|
69
|
-
logger.debug(
|
|
70
|
-
"Does NOT implement IProvideClassInfo, trying IProvideClassInfo2"
|
|
71
|
-
)
|
|
72
|
-
pci = punk.QueryInterface(typeinfo.IProvideClassInfo2)
|
|
73
|
-
logger.debug("Does implement IProvideClassInfo2")
|
|
74
|
-
tinfo = pci.GetClassInfo() # TypeInfo for the CoClass
|
|
75
|
-
# find the interface marked as default
|
|
76
|
-
ta = tinfo.GetTypeAttr()
|
|
77
|
-
for index in range(ta.cImplTypes):
|
|
78
|
-
if tinfo.GetImplTypeFlags(index) == 1:
|
|
79
|
-
break
|
|
80
|
-
else:
|
|
81
|
-
if ta.cImplTypes != 1:
|
|
82
|
-
# Hm, should we use dynamic now?
|
|
83
|
-
raise TypeError("No default interface found")
|
|
84
|
-
# Only one interface implemented, use that (even if
|
|
85
|
-
# not marked as default).
|
|
86
|
-
index = 0
|
|
87
|
-
href = tinfo.GetRefTypeOfImplType(index)
|
|
88
|
-
tinfo = tinfo.GetRefTypeInfo(href)
|
|
89
|
-
except comtypes.COMError:
|
|
90
|
-
logger.debug("Does NOT implement IProvideClassInfo/IProvideClassInfo2")
|
|
91
|
-
try:
|
|
92
|
-
pdisp = punk.QueryInterface(automation.IDispatch)
|
|
93
|
-
except comtypes.COMError:
|
|
94
|
-
logger.debug("No Dispatch interface: %s", punk)
|
|
95
|
-
return punk
|
|
96
|
-
try:
|
|
97
|
-
tinfo = pdisp.GetTypeInfo(0)
|
|
98
|
-
except comtypes.COMError:
|
|
99
|
-
pdisp = comtypes.client.dynamic.Dispatch(pdisp)
|
|
100
|
-
logger.debug("IDispatch.GetTypeInfo(0) failed: %s" % pdisp)
|
|
101
|
-
return pdisp
|
|
102
|
-
typeattr = tinfo.GetTypeAttr()
|
|
103
|
-
logger.debug("Default interface is %s", typeattr.guid)
|
|
104
|
-
try:
|
|
105
|
-
punk.QueryInterface(comtypes.IUnknown, typeattr.guid)
|
|
106
|
-
except comtypes.COMError:
|
|
107
|
-
logger.debug("Does not implement default interface, returning dynamic object")
|
|
108
|
-
return comtypes.client.dynamic.Dispatch(punk)
|
|
109
|
-
|
|
110
|
-
itf_name = tinfo.GetDocumentation(-1)[0] # interface name
|
|
111
|
-
tlib = tinfo.GetContainingTypeLib()[0] # typelib
|
|
112
|
-
|
|
113
|
-
# import the wrapper, generating it on demand
|
|
114
|
-
mod = GetModule(tlib)
|
|
115
|
-
# Python interface class
|
|
116
|
-
interface = getattr(mod, itf_name)
|
|
117
|
-
logger.debug("Implements default interface from typeinfo %s", interface)
|
|
118
|
-
# QI for this interface
|
|
119
|
-
# XXX
|
|
120
|
-
# What to do if this fails?
|
|
121
|
-
# In the following example the engine.Eval() call returns
|
|
122
|
-
# such an object.
|
|
123
|
-
#
|
|
124
|
-
# engine = CreateObject("MsScriptControl.ScriptControl")
|
|
125
|
-
# engine.Language = "JScript"
|
|
126
|
-
# engine.Eval("[1, 2, 3]")
|
|
127
|
-
#
|
|
128
|
-
# Could the above code, as an optimization, check that QI works,
|
|
129
|
-
# *before* generating the wrapper module?
|
|
130
|
-
result = punk.QueryInterface(interface)
|
|
131
|
-
logger.debug("Final result is %s", result)
|
|
132
|
-
return result
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
# backwards compatibility:
|
|
136
|
-
wrap = GetBestInterface
|
|
137
|
-
|
|
138
|
-
# Should we do this for POINTER(IUnknown) also?
|
|
139
|
-
ctypes.POINTER(automation.IDispatch).__ctypes_from_outparam__ = wrap_outparam # type: ignore
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
################################################################
|
|
143
|
-
#
|
|
144
|
-
# Object creation
|
|
145
|
-
#
|
|
146
|
-
@overload
|
|
147
|
-
def GetActiveObject(progid: _UnionT[str, CoClass, GUID]) -> Any: ...
|
|
148
|
-
@overload
|
|
149
|
-
def GetActiveObject(
|
|
150
|
-
progid: _UnionT[str, CoClass, GUID], interface: Type[_T_IUnknown]
|
|
151
|
-
) -> _T_IUnknown: ...
|
|
152
|
-
def GetActiveObject(
|
|
153
|
-
progid: _UnionT[str, CoClass, GUID],
|
|
154
|
-
interface: Optional[Type[IUnknown]] = None,
|
|
155
|
-
dynamic: bool = False,
|
|
156
|
-
) -> Any:
|
|
157
|
-
"""Return a pointer to a running COM object that has been
|
|
158
|
-
registered with COM.
|
|
159
|
-
|
|
160
|
-
'progid' may be a string like "Excel.Application",
|
|
161
|
-
a string specifying a clsid, a GUID instance, or an object with
|
|
162
|
-
a _clsid_ attribute which should be any of the above.
|
|
163
|
-
'interface' allows to force a certain interface.
|
|
164
|
-
'dynamic=True' will return a dynamic dispatch object.
|
|
165
|
-
"""
|
|
166
|
-
clsid = GUID.from_progid(progid)
|
|
167
|
-
if dynamic:
|
|
168
|
-
if interface is not None:
|
|
169
|
-
raise ValueError("interface and dynamic are mutually exclusive")
|
|
170
|
-
interface = automation.IDispatch
|
|
171
|
-
elif interface is None:
|
|
172
|
-
interface = getattr(progid, "_com_interfaces_", [None])[0]
|
|
173
|
-
obj = comtypes.GetActiveObject(clsid, interface=interface)
|
|
174
|
-
if dynamic:
|
|
175
|
-
return comtypes.client.dynamic.Dispatch(obj)
|
|
176
|
-
return _manage(obj, clsid, interface=interface)
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
def _manage(
|
|
180
|
-
obj: Any, clsid: Optional[GUID], interface: Optional[Type[IUnknown]]
|
|
181
|
-
) -> Any:
|
|
182
|
-
obj.__dict__["__clsid"] = str(clsid)
|
|
183
|
-
if interface is None:
|
|
184
|
-
obj = GetBestInterface(obj)
|
|
185
|
-
return obj
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
if TYPE_CHECKING:
|
|
189
|
-
|
|
190
|
-
@overload
|
|
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: ...
|
|
197
|
-
@overload
|
|
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
|
-
|
|
205
|
-
|
|
206
|
-
def GetClassObject(progid, clsctx=None, pServerInfo=None, interface=None):
|
|
207
|
-
# type: (_UnionT[str, CoClass, GUID], Optional[int], Optional[comtypes.COSERVERINFO], Optional[Type[IUnknown]]) -> IUnknown
|
|
208
|
-
"""Create and return the class factory for a COM object.
|
|
209
|
-
|
|
210
|
-
'clsctx' specifies how to create the object, use the CLSCTX_... constants.
|
|
211
|
-
'pServerInfo', if used, must be a pointer to a comtypes.COSERVERINFO instance
|
|
212
|
-
'interface' may be used to request an interface other than IClassFactory
|
|
213
|
-
"""
|
|
214
|
-
clsid = GUID.from_progid(progid)
|
|
215
|
-
return comtypes.CoGetClassObject(clsid, clsctx, pServerInfo, interface)
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
@overload
|
|
219
|
-
def CreateObject(progid: _UnionT[str, Type[CoClass], GUID]) -> Any: ...
|
|
220
|
-
@overload
|
|
221
|
-
def CreateObject(
|
|
222
|
-
progid: _UnionT[str, Type[CoClass], GUID],
|
|
223
|
-
clsctx: Optional[int] = None,
|
|
224
|
-
machine: Optional[str] = None,
|
|
225
|
-
interface: Optional[Type[_T_IUnknown]] = None,
|
|
226
|
-
dynamic: bool = ...,
|
|
227
|
-
pServerInfo: Optional[comtypes.COSERVERINFO] = None,
|
|
228
|
-
) -> _T_IUnknown: ...
|
|
229
|
-
def CreateObject(
|
|
230
|
-
progid: _UnionT[str, Type[CoClass], GUID], # which object to create
|
|
231
|
-
clsctx: Optional[int] = None, # how to create the object
|
|
232
|
-
machine: Optional[str] = None, # where to create the object
|
|
233
|
-
interface: Optional[Type[IUnknown]] = None, # the interface we want
|
|
234
|
-
dynamic: bool = False, # use dynamic dispatch
|
|
235
|
-
pServerInfo: Optional[
|
|
236
|
-
comtypes.COSERVERINFO
|
|
237
|
-
] = None, # server info struct for remoting
|
|
238
|
-
) -> Any:
|
|
239
|
-
"""Create a COM object from 'progid', and try to QueryInterface()
|
|
240
|
-
it to the most useful interface, generating typelib support on
|
|
241
|
-
demand. A pointer to this interface is returned.
|
|
242
|
-
|
|
243
|
-
'progid' may be a string like "InternetExplorer.Application",
|
|
244
|
-
a string specifying a clsid, a GUID instance, or an object with
|
|
245
|
-
a _clsid_ attribute which should be any of the above.
|
|
246
|
-
'clsctx' specifies how to create the object, use the CLSCTX_... constants.
|
|
247
|
-
'machine' allows to specify a remote machine to create the object on.
|
|
248
|
-
'interface' allows to force a certain interface
|
|
249
|
-
'dynamic=True' will return a dynamic dispatch object
|
|
250
|
-
'pServerInfo', if used, must be a pointer to a comtypes.COSERVERINFO instance
|
|
251
|
-
This supercedes 'machine'.
|
|
252
|
-
|
|
253
|
-
You can also later request to receive events with GetEvents().
|
|
254
|
-
"""
|
|
255
|
-
clsid = GUID.from_progid(progid)
|
|
256
|
-
logger.debug("%s -> %s", progid, clsid)
|
|
257
|
-
if dynamic:
|
|
258
|
-
if interface:
|
|
259
|
-
raise ValueError("interface and dynamic are mutually exclusive")
|
|
260
|
-
interface = automation.IDispatch
|
|
261
|
-
elif interface is None:
|
|
262
|
-
interface = getattr(progid, "_com_interfaces_", [None])[0]
|
|
263
|
-
if machine is None and pServerInfo is None:
|
|
264
|
-
logger.debug(
|
|
265
|
-
"CoCreateInstance(%s, clsctx=%s, interface=%s)", clsid, clsctx, interface
|
|
266
|
-
)
|
|
267
|
-
obj = comtypes.CoCreateInstance(clsid, clsctx=clsctx, interface=interface)
|
|
268
|
-
else:
|
|
269
|
-
logger.debug(
|
|
270
|
-
"CoCreateInstanceEx(%s, clsctx=%s, interface=%s, machine=%s,\
|
|
271
|
-
pServerInfo=%s)",
|
|
272
|
-
clsid,
|
|
273
|
-
clsctx,
|
|
274
|
-
interface,
|
|
275
|
-
machine,
|
|
276
|
-
pServerInfo,
|
|
277
|
-
)
|
|
278
|
-
if machine is not None and pServerInfo is not None:
|
|
279
|
-
msg = "You cannot set both the machine name and server info."
|
|
280
|
-
raise ValueError(msg)
|
|
281
|
-
obj = comtypes.CoCreateInstanceEx(
|
|
282
|
-
clsid,
|
|
283
|
-
clsctx=clsctx,
|
|
284
|
-
interface=interface,
|
|
285
|
-
machine=machine,
|
|
286
|
-
pServerInfo=pServerInfo,
|
|
287
|
-
)
|
|
288
|
-
if dynamic:
|
|
289
|
-
return comtypes.client.dynamic.Dispatch(obj)
|
|
290
|
-
return _manage(obj, clsid, interface=interface)
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
@overload
|
|
294
|
-
def CoGetObject(displayname: str, interface: Type[_T_IUnknown]) -> _T_IUnknown: ...
|
|
295
|
-
@overload
|
|
296
|
-
def CoGetObject(
|
|
297
|
-
displayname: str, interface: None = None, dynamic: bool = False
|
|
298
|
-
) -> Any: ...
|
|
299
|
-
def CoGetObject(
|
|
300
|
-
displayname: str,
|
|
301
|
-
interface: Optional[Type[comtypes.IUnknown]] = None,
|
|
302
|
-
dynamic: bool = False,
|
|
303
|
-
) -> Any:
|
|
304
|
-
"""Create an object by calling CoGetObject(displayname).
|
|
305
|
-
|
|
306
|
-
Additional parameters have the same meaning as in CreateObject().
|
|
307
|
-
"""
|
|
308
|
-
if dynamic:
|
|
309
|
-
if interface is not None:
|
|
310
|
-
raise ValueError("interface and dynamic are mutually exclusive")
|
|
311
|
-
interface = automation.IDispatch
|
|
312
|
-
punk = comtypes.CoGetObject(displayname, interface)
|
|
313
|
-
if dynamic:
|
|
314
|
-
return comtypes.client.dynamic.Dispatch(punk)
|
|
315
|
-
return _manage(punk, clsid=None, interface=interface)
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
# fmt: off
|
|
319
|
-
__all__ = [
|
|
320
|
-
"CreateObject", "GetActiveObject", "CoGetObject", "GetEvents",
|
|
321
|
-
"ShowEvents", "PumpEvents", "GetModule", "GetClassObject",
|
|
322
|
-
]
|
|
323
|
-
# fmt: on
|