comtypes 1.4.8__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.
Files changed (154) hide show
  1. {comtypes-1.4.8 → comtypes-1.4.10}/CHANGES.txt +40 -0
  2. {comtypes-1.4.8/comtypes.egg-info → comtypes-1.4.10}/PKG-INFO +4 -3
  3. {comtypes-1.4.8 → comtypes-1.4.10}/README.md +1 -1
  4. {comtypes-1.4.8 → comtypes-1.4.10}/comtypes/GUID.py +38 -16
  5. {comtypes-1.4.8 → comtypes-1.4.10}/comtypes/__init__.py +36 -16
  6. comtypes-1.4.10/comtypes/_comobject.py +562 -0
  7. {comtypes-1.4.8 → comtypes-1.4.10}/comtypes/_memberspec.py +93 -13
  8. {comtypes-1.4.8 → comtypes-1.4.10}/comtypes/_meta.py +1 -0
  9. comtypes-1.4.10/comtypes/_post_coinit/_cominterface_meta_patcher.py +152 -0
  10. {comtypes-1.4.8 → comtypes-1.4.10}/comtypes/_post_coinit/bstr.py +12 -5
  11. comtypes-1.4.8/comtypes/_py_instance_method.py → comtypes-1.4.10/comtypes/_post_coinit/instancemethod.py +1 -2
  12. {comtypes-1.4.8 → comtypes-1.4.10}/comtypes/_post_coinit/misc.py +60 -25
  13. {comtypes-1.4.8 → comtypes-1.4.10}/comtypes/_post_coinit/unknwn.py +26 -176
  14. {comtypes-1.4.8 → comtypes-1.4.10}/comtypes/_safearray.py +3 -4
  15. comtypes-1.4.10/comtypes/_vtbl.py +448 -0
  16. {comtypes-1.4.8 → comtypes-1.4.10}/comtypes/automation.py +46 -49
  17. comtypes-1.4.10/comtypes/client/__init__.py +42 -0
  18. comtypes-1.4.10/comtypes/client/_activeobj.py +46 -0
  19. {comtypes-1.4.8 → comtypes-1.4.10}/comtypes/client/_code_cache.py +10 -5
  20. {comtypes-1.4.8 → comtypes-1.4.10}/comtypes/client/_constants.py +1 -1
  21. comtypes-1.4.10/comtypes/client/_create.py +147 -0
  22. {comtypes-1.4.8 → comtypes-1.4.10}/comtypes/client/_events.py +58 -13
  23. {comtypes-1.4.8 → comtypes-1.4.10}/comtypes/client/_generate.py +7 -11
  24. comtypes-1.4.10/comtypes/client/_managing.py +114 -0
  25. {comtypes-1.4.8 → comtypes-1.4.10}/comtypes/client/dynamic.py +2 -3
  26. {comtypes-1.4.8 → comtypes-1.4.10}/comtypes/client/lazybind.py +12 -13
  27. {comtypes-1.4.8 → comtypes-1.4.10}/comtypes/connectionpoints.py +2 -1
  28. {comtypes-1.4.8 → comtypes-1.4.10}/comtypes/errorinfo.py +22 -9
  29. {comtypes-1.4.8 → comtypes-1.4.10}/comtypes/git.py +5 -5
  30. {comtypes-1.4.8 → comtypes-1.4.10}/comtypes/hints.pyi +7 -15
  31. {comtypes-1.4.8 → comtypes-1.4.10}/comtypes/logutil.py +15 -3
  32. {comtypes-1.4.8 → comtypes-1.4.10}/comtypes/messageloop.py +1 -1
  33. {comtypes-1.4.8 → comtypes-1.4.10}/comtypes/persist.py +3 -5
  34. {comtypes-1.4.8 → comtypes-1.4.10}/comtypes/safearray.py +17 -5
  35. comtypes-1.4.10/comtypes/server/__init__.py +104 -0
  36. {comtypes-1.4.8 → comtypes-1.4.10}/comtypes/server/automation.py +1 -2
  37. {comtypes-1.4.8 → comtypes-1.4.10}/comtypes/server/connectionpoints.py +5 -5
  38. {comtypes-1.4.8 → comtypes-1.4.10}/comtypes/server/inprocserver.py +25 -17
  39. {comtypes-1.4.8 → comtypes-1.4.10}/comtypes/server/localserver.py +49 -19
  40. comtypes-1.4.10/comtypes/server/register.py +478 -0
  41. comtypes-1.4.10/comtypes/server/w_getopt.py +48 -0
  42. {comtypes-1.4.8 → comtypes-1.4.10}/comtypes/shelllink.py +16 -33
  43. {comtypes-1.4.8 → comtypes-1.4.10}/comtypes/stream.py +7 -4
  44. {comtypes-1.4.8 → comtypes-1.4.10}/comtypes/test/TestComServer.py +6 -7
  45. {comtypes-1.4.8 → comtypes-1.4.10}/comtypes/test/TestDispServer.py +4 -2
  46. {comtypes-1.4.8 → comtypes-1.4.10}/comtypes/test/__init__.py +10 -12
  47. comtypes-1.4.10/comtypes/test/find_memleak.py +72 -0
  48. {comtypes-1.4.8 → comtypes-1.4.10}/comtypes/test/runtests.py +1 -0
  49. {comtypes-1.4.8 → comtypes-1.4.10}/comtypes/test/setup.py +2 -1
  50. {comtypes-1.4.8 → comtypes-1.4.10}/comtypes/test/test_BSTR.py +10 -23
  51. {comtypes-1.4.8 → comtypes-1.4.10}/comtypes/test/test_GUID.py +1 -0
  52. {comtypes-1.4.8 → comtypes-1.4.10}/comtypes/test/test_QueryService.py +1 -0
  53. {comtypes-1.4.8 → comtypes-1.4.10}/comtypes/test/test_agilent.py +4 -3
  54. {comtypes-1.4.8 → comtypes-1.4.10}/comtypes/test/test_avmc.py +1 -1
  55. {comtypes-1.4.8 → comtypes-1.4.10}/comtypes/test/test_basic.py +12 -6
  56. {comtypes-1.4.8 → comtypes-1.4.10}/comtypes/test/test_casesensitivity.py +3 -5
  57. {comtypes-1.4.8 → comtypes-1.4.10}/comtypes/test/test_clear_cache.py +1 -1
  58. {comtypes-1.4.8 → comtypes-1.4.10}/comtypes/test/test_client.py +2 -2
  59. {comtypes-1.4.8 → comtypes-1.4.10}/comtypes/test/test_client_dynamic.py +2 -2
  60. {comtypes-1.4.8 → comtypes-1.4.10}/comtypes/test/test_client_regenerate_modules.py +2 -2
  61. {comtypes-1.4.8 → comtypes-1.4.10}/comtypes/test/test_collections.py +4 -4
  62. comtypes-1.4.10/comtypes/test/test_comobject.py +146 -0
  63. comtypes-1.4.10/comtypes/test/test_comserver.py +349 -0
  64. {comtypes-1.4.8 → comtypes-1.4.10}/comtypes/test/test_createwrappers.py +2 -4
  65. {comtypes-1.4.8 → comtypes-1.4.10}/comtypes/test/test_dispifc_records.py +1 -1
  66. {comtypes-1.4.8 → comtypes-1.4.10}/comtypes/test/test_dispifc_safearrays.py +1 -1
  67. comtypes-1.4.10/comtypes/test/test_dispinterface.py +153 -0
  68. {comtypes-1.4.8 → comtypes-1.4.10}/comtypes/test/test_dyndispatch.py +1 -0
  69. {comtypes-1.4.8 → comtypes-1.4.10}/comtypes/test/test_excel.py +22 -12
  70. {comtypes-1.4.8 → comtypes-1.4.10}/comtypes/test/test_findgendir.py +1 -2
  71. {comtypes-1.4.8 → comtypes-1.4.10}/comtypes/test/test_getactiveobj.py +4 -4
  72. {comtypes-1.4.8 → comtypes-1.4.10}/comtypes/test/test_ie.py +19 -9
  73. {comtypes-1.4.8 → comtypes-1.4.10}/comtypes/test/test_ienum.py +2 -2
  74. {comtypes-1.4.8 → comtypes-1.4.10}/comtypes/test/test_imfattributes.py +13 -3
  75. {comtypes-1.4.8 → comtypes-1.4.10}/comtypes/test/test_inout_args.py +8 -5
  76. {comtypes-1.4.8 → comtypes-1.4.10}/comtypes/test/test_midl_safearray_create.py +14 -4
  77. {comtypes-1.4.8 → comtypes-1.4.10}/comtypes/test/test_monikers.py +23 -9
  78. {comtypes-1.4.8 → comtypes-1.4.10}/comtypes/test/test_msscript.py +2 -1
  79. {comtypes-1.4.8 → comtypes-1.4.10}/comtypes/test/test_npsupport.py +4 -4
  80. {comtypes-1.4.8 → comtypes-1.4.10}/comtypes/test/test_outparam.py +37 -14
  81. {comtypes-1.4.8 → comtypes-1.4.10}/comtypes/test/test_persist.py +2 -4
  82. {comtypes-1.4.8 → comtypes-1.4.10}/comtypes/test/test_recordinfo.py +1 -1
  83. {comtypes-1.4.8 → comtypes-1.4.10}/comtypes/test/test_safearray.py +1 -90
  84. {comtypes-1.4.8 → comtypes-1.4.10}/comtypes/test/test_sapi.py +4 -1
  85. comtypes-1.4.10/comtypes/test/test_server.py +350 -0
  86. comtypes-1.4.10/comtypes/test/test_server_register.py +524 -0
  87. {comtypes-1.4.8 → comtypes-1.4.10}/comtypes/test/test_shelllink.py +2 -3
  88. {comtypes-1.4.8 → comtypes-1.4.10}/comtypes/test/test_showevents.py +7 -17
  89. {comtypes-1.4.8 → comtypes-1.4.10}/comtypes/test/test_storage.py +12 -6
  90. {comtypes-1.4.8 → comtypes-1.4.10}/comtypes/test/test_stream.py +16 -5
  91. {comtypes-1.4.8 → comtypes-1.4.10}/comtypes/test/test_subinterface.py +4 -2
  92. {comtypes-1.4.8 → comtypes-1.4.10}/comtypes/test/test_typeannotator.py +1 -2
  93. {comtypes-1.4.8 → comtypes-1.4.10}/comtypes/test/test_typeinfo.py +19 -7
  94. {comtypes-1.4.8 → comtypes-1.4.10}/comtypes/test/test_urlhistory.py +7 -4
  95. {comtypes-1.4.8 → comtypes-1.4.10}/comtypes/test/test_variant.py +3 -19
  96. comtypes-1.4.10/comtypes/test/test_w_getopt.py +29 -0
  97. {comtypes-1.4.8 → comtypes-1.4.10}/comtypes/test/test_win32com_interop.py +80 -36
  98. {comtypes-1.4.8 → comtypes-1.4.10}/comtypes/test/test_wmi.py +0 -3
  99. {comtypes-1.4.8 → comtypes-1.4.10}/comtypes/test/test_word.py +1 -1
  100. {comtypes-1.4.8 → comtypes-1.4.10}/comtypes/tools/codegenerator/codegenerator.py +166 -440
  101. comtypes-1.4.10/comtypes/tools/codegenerator/comments.py +79 -0
  102. comtypes-1.4.10/comtypes/tools/codegenerator/heads.py +192 -0
  103. {comtypes-1.4.8 → comtypes-1.4.10}/comtypes/tools/codegenerator/helpers.py +11 -14
  104. {comtypes-1.4.8 → comtypes-1.4.10}/comtypes/tools/codegenerator/namespaces.py +13 -5
  105. {comtypes-1.4.8 → comtypes-1.4.10}/comtypes/tools/codegenerator/packing.py +4 -4
  106. {comtypes-1.4.8 → comtypes-1.4.10}/comtypes/tools/codegenerator/typeannotator.py +19 -9
  107. {comtypes-1.4.8 → comtypes-1.4.10}/comtypes/tools/tlbparser.py +22 -23
  108. {comtypes-1.4.8 → comtypes-1.4.10}/comtypes/tools/typedesc.py +4 -8
  109. {comtypes-1.4.8 → comtypes-1.4.10}/comtypes/tools/typedesc_base.py +2 -2
  110. {comtypes-1.4.8 → comtypes-1.4.10}/comtypes/typeinfo.py +159 -63
  111. {comtypes-1.4.8 → comtypes-1.4.10}/comtypes/viewobject.py +3 -9
  112. {comtypes-1.4.8 → comtypes-1.4.10/comtypes.egg-info}/PKG-INFO +4 -3
  113. {comtypes-1.4.8 → comtypes-1.4.10}/comtypes.egg-info/SOURCES.txt +11 -3
  114. {comtypes-1.4.8 → comtypes-1.4.10}/pyproject.toml +12 -19
  115. comtypes-1.4.8/comtypes/_comobject.py +0 -833
  116. comtypes-1.4.8/comtypes/_idl_stuff.py +0 -67
  117. comtypes-1.4.8/comtypes/client/__init__.py +0 -323
  118. comtypes-1.4.8/comtypes/server/__init__.py +0 -70
  119. comtypes-1.4.8/comtypes/server/register.py +0 -431
  120. comtypes-1.4.8/comtypes/server/w_getopt.py +0 -75
  121. comtypes-1.4.8/comtypes/test/find_memleak.py +0 -76
  122. comtypes-1.4.8/comtypes/test/test_comserver.py +0 -239
  123. comtypes-1.4.8/comtypes/test/test_dispinterface.py +0 -137
  124. comtypes-1.4.8/comtypes/test/test_propputref.py +0 -40
  125. comtypes-1.4.8/comtypes/test/test_server.py +0 -354
  126. {comtypes-1.4.8 → comtypes-1.4.10}/LICENSE.txt +0 -0
  127. {comtypes-1.4.8 → comtypes-1.4.10}/MANIFEST.in +0 -0
  128. {comtypes-1.4.8 → comtypes-1.4.10}/comtypes/_npsupport.py +0 -0
  129. {comtypes-1.4.8 → comtypes-1.4.10}/comtypes/_post_coinit/__init__.py +0 -0
  130. {comtypes-1.4.8 → comtypes-1.4.10}/comtypes/_tlib_version_checker.py +0 -0
  131. {comtypes-1.4.8 → comtypes-1.4.10}/comtypes/clear_cache.py +0 -0
  132. {comtypes-1.4.8 → comtypes-1.4.10}/comtypes/hresult.py +0 -0
  133. {comtypes-1.4.8 → comtypes-1.4.10}/comtypes/patcher.py +0 -0
  134. {comtypes-1.4.8 → comtypes-1.4.10}/comtypes/test/TestComServer.idl +0 -0
  135. {comtypes-1.4.8 → comtypes-1.4.10}/comtypes/test/TestComServer.tlb +0 -0
  136. {comtypes-1.4.8 → comtypes-1.4.10}/comtypes/test/TestDispServer.idl +0 -0
  137. {comtypes-1.4.8 → comtypes-1.4.10}/comtypes/test/TestDispServer.tlb +0 -0
  138. {comtypes-1.4.8 → comtypes-1.4.10}/comtypes/test/mylib.idl +0 -0
  139. {comtypes-1.4.8 → comtypes-1.4.10}/comtypes/test/mylib.tlb +0 -0
  140. {comtypes-1.4.8 → comtypes-1.4.10}/comtypes/test/mytypelib.idl +0 -0
  141. {comtypes-1.4.8 → comtypes-1.4.10}/comtypes/test/test_DISPPARAMS.py +0 -0
  142. {comtypes-1.4.8 → comtypes-1.4.10}/comtypes/test/test_dict.py +0 -0
  143. {comtypes-1.4.8 → comtypes-1.4.10}/comtypes/test/test_jscript.js +0 -0
  144. {comtypes-1.4.8 → comtypes-1.4.10}/comtypes/test/test_pump_events.py +0 -0
  145. {comtypes-1.4.8 → comtypes-1.4.10}/comtypes/test/urlhist.tlb +0 -0
  146. {comtypes-1.4.8 → comtypes-1.4.10}/comtypes/tools/__init__.py +0 -0
  147. {comtypes-1.4.8 → comtypes-1.4.10}/comtypes/tools/codegenerator/__init__.py +0 -0
  148. {comtypes-1.4.8 → comtypes-1.4.10}/comtypes/tools/codegenerator/modulenamer.py +0 -0
  149. {comtypes-1.4.8 → comtypes-1.4.10}/comtypes/util.py +0 -0
  150. {comtypes-1.4.8 → comtypes-1.4.10}/comtypes.egg-info/dependency_links.txt +0 -0
  151. {comtypes-1.4.8 → comtypes-1.4.10}/comtypes.egg-info/entry_points.txt +0 -0
  152. {comtypes-1.4.8 → comtypes-1.4.10}/comtypes.egg-info/top_level.txt +0 -0
  153. {comtypes-1.4.8 → comtypes-1.4.10}/setup.cfg +0 -0
  154. {comtypes-1.4.8 → comtypes-1.4.10}/setup.py +0 -0
@@ -1,67 +0,0 @@
1
- from comtypes._memberspec import _ComMemberSpec, _DispMemberSpec, _resolve_argspec
2
-
3
-
4
- class helpstring(str):
5
- "Specifies the helpstring for a COM method or property."
6
-
7
-
8
- class defaultvalue(object):
9
- "Specifies the default value for parameters marked optional."
10
-
11
- def __init__(self, value):
12
- self.value = value
13
-
14
-
15
- class dispid(int):
16
- "Specifies the DISPID of a method or property."
17
-
18
-
19
- # XXX STDMETHOD, COMMETHOD, DISPMETHOD, and DISPPROPERTY should return
20
- # instances with more methods or properties, and should not behave as an unpackable.
21
-
22
-
23
- def STDMETHOD(restype, name, argtypes=()) -> _ComMemberSpec:
24
- "Specifies a COM method slot without idlflags"
25
- return _ComMemberSpec(restype, name, argtypes, None, (), None)
26
-
27
-
28
- def DISPMETHOD(idlflags, restype, name, *argspec) -> _DispMemberSpec:
29
- "Specifies a method of a dispinterface"
30
- return _DispMemberSpec("DISPMETHOD", name, tuple(idlflags), restype, argspec)
31
-
32
-
33
- def DISPPROPERTY(idlflags, proptype, name) -> _DispMemberSpec:
34
- "Specifies a property of a dispinterface"
35
- return _DispMemberSpec("DISPPROPERTY", name, tuple(idlflags), proptype, ())
36
-
37
-
38
- # tuple(idlflags) is for the method itself: (dispid, 'readonly')
39
-
40
- # sample generated code:
41
- # DISPPROPERTY([5, 'readonly'], OLE_YSIZE_HIMETRIC, 'Height'),
42
- # DISPMETHOD(
43
- # [6], None, 'Render', ([], c_int, 'hdc'), ([], c_int, 'x'), ([], c_int, 'y')
44
- # )
45
-
46
-
47
- def COMMETHOD(idlflags, restype, methodname, *argspec) -> _ComMemberSpec:
48
- """Specifies a COM method slot with idlflags.
49
-
50
- XXX should explain the sematics of the arguments.
51
- """
52
- # collect all helpstring instances
53
- # We should suppress docstrings when Python is started with -OO
54
- # join them together(does this make sense?) and replace by None if empty.
55
- helptext = "".join(t for t in idlflags if isinstance(t, helpstring)) or None
56
- paramflags, argtypes = _resolve_argspec(argspec)
57
- if "propget" in idlflags:
58
- name = "_get_%s" % methodname
59
- elif "propput" in idlflags:
60
- name = "_set_%s" % methodname
61
- elif "propputref" in idlflags:
62
- name = "_setref_%s" % methodname
63
- else:
64
- name = methodname
65
- return _ComMemberSpec(
66
- restype, name, argtypes, paramflags, tuple(idlflags), helptext
67
- )
@@ -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
@@ -1,70 +0,0 @@
1
- import comtypes.client, ctypes
2
-
3
-
4
- ################################################################
5
- # Interfaces
6
- class IClassFactory(comtypes.IUnknown):
7
- _iid_ = comtypes.GUID("{00000001-0000-0000-C000-000000000046}")
8
- _methods_ = [
9
- comtypes.STDMETHOD(
10
- comtypes.HRESULT,
11
- "CreateInstance",
12
- [
13
- ctypes.POINTER(comtypes.IUnknown),
14
- ctypes.POINTER(comtypes.GUID),
15
- ctypes.POINTER(ctypes.c_void_p),
16
- ],
17
- ),
18
- comtypes.STDMETHOD(comtypes.HRESULT, "LockServer", [ctypes.c_int]),
19
- ]
20
-
21
- def CreateInstance(self, punkouter=None, interface=None, dynamic=False):
22
- if dynamic:
23
- if interface is not None:
24
- raise ValueError("interface and dynamic are mutually exclusive")
25
- realInterface = comtypes.automation.IDispatch
26
- elif interface is None:
27
- realInterface = comtypes.IUnknown
28
- else:
29
- realInterface = interface
30
- obj = ctypes.POINTER(realInterface)()
31
- self.__com_CreateInstance(punkouter, realInterface._iid_, ctypes.byref(obj))
32
- if dynamic:
33
- return comtypes.client.dynamic.Dispatch(obj)
34
- elif interface is None:
35
- # An interface was not specified, so return the best.
36
- return comtypes.client.GetBestInterface(obj)
37
- # An interface was specified and obj is already that interface.
38
- return obj
39
-
40
-
41
- # class IExternalConnection(IUnknown):
42
- # _iid_ = GUID("{00000019-0000-0000-C000-000000000046}")
43
- # _methods_ = [
44
- # STDMETHOD(HRESULT, "AddConnection", [c_ulong, c_ulong]),
45
- # STDMETHOD(HRESULT, "ReleaseConnection", [c_ulong, c_ulong, c_ulong])]
46
-
47
- # The following code is untested:
48
-
49
- ACTIVEOBJECT_STRONG = 0x0
50
- ACTIVEOBJECT_WEAK = 0x1
51
-
52
- oleaut32 = ctypes.oledll.oleaut32
53
-
54
-
55
- def RegisterActiveObject(comobj, weak=True):
56
- punk = comobj._com_pointers_[comtypes.IUnknown._iid_]
57
- clsid = comobj._reg_clsid_
58
- if weak:
59
- flags = ACTIVEOBJECT_WEAK
60
- else:
61
- flags = ACTIVEOBJECT_STRONG
62
- handle = ctypes.c_ulong()
63
- oleaut32.RegisterActiveObject(
64
- punk, ctypes.byref(clsid), flags, ctypes.byref(handle)
65
- )
66
- return handle.value
67
-
68
-
69
- def RevokeActiveObject(handle):
70
- oleaut32.RevokeActiveObject(handle, None)