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.
Files changed (146) hide show
  1. {comtypes-1.4.9 → comtypes-1.4.10}/CHANGES.txt +19 -0
  2. {comtypes-1.4.9/comtypes.egg-info → comtypes-1.4.10}/PKG-INFO +3 -2
  3. {comtypes-1.4.9 → comtypes-1.4.10}/comtypes/GUID.py +34 -13
  4. {comtypes-1.4.9 → comtypes-1.4.10}/comtypes/__init__.py +22 -13
  5. {comtypes-1.4.9 → comtypes-1.4.10}/comtypes/_comobject.py +69 -14
  6. {comtypes-1.4.9 → comtypes-1.4.10}/comtypes/_memberspec.py +14 -6
  7. {comtypes-1.4.9 → comtypes-1.4.10}/comtypes/_meta.py +1 -0
  8. {comtypes-1.4.9 → comtypes-1.4.10}/comtypes/_post_coinit/_cominterface_meta_patcher.py +0 -1
  9. {comtypes-1.4.9 → comtypes-1.4.10}/comtypes/_post_coinit/bstr.py +12 -5
  10. {comtypes-1.4.9 → comtypes-1.4.10}/comtypes/_post_coinit/instancemethod.py +1 -2
  11. {comtypes-1.4.9 → comtypes-1.4.10}/comtypes/_post_coinit/misc.py +59 -24
  12. {comtypes-1.4.9 → comtypes-1.4.10}/comtypes/_post_coinit/unknwn.py +2 -6
  13. {comtypes-1.4.9 → comtypes-1.4.10}/comtypes/_safearray.py +2 -2
  14. {comtypes-1.4.9 → comtypes-1.4.10}/comtypes/automation.py +10 -4
  15. comtypes-1.4.10/comtypes/client/__init__.py +42 -0
  16. comtypes-1.4.10/comtypes/client/_activeobj.py +46 -0
  17. {comtypes-1.4.9 → comtypes-1.4.10}/comtypes/client/_code_cache.py +6 -1
  18. comtypes-1.4.10/comtypes/client/_create.py +147 -0
  19. {comtypes-1.4.9 → comtypes-1.4.10}/comtypes/client/_events.py +57 -12
  20. {comtypes-1.4.9 → comtypes-1.4.10}/comtypes/client/_generate.py +3 -3
  21. comtypes-1.4.10/comtypes/client/_managing.py +114 -0
  22. {comtypes-1.4.9 → comtypes-1.4.10}/comtypes/client/dynamic.py +2 -3
  23. {comtypes-1.4.9 → comtypes-1.4.10}/comtypes/client/lazybind.py +10 -11
  24. {comtypes-1.4.9 → comtypes-1.4.10}/comtypes/connectionpoints.py +2 -1
  25. {comtypes-1.4.9 → comtypes-1.4.10}/comtypes/errorinfo.py +20 -7
  26. {comtypes-1.4.9 → comtypes-1.4.10}/comtypes/git.py +4 -3
  27. {comtypes-1.4.9 → comtypes-1.4.10}/comtypes/logutil.py +15 -3
  28. {comtypes-1.4.9 → comtypes-1.4.10}/comtypes/messageloop.py +1 -1
  29. {comtypes-1.4.9 → comtypes-1.4.10}/comtypes/persist.py +3 -5
  30. {comtypes-1.4.9 → comtypes-1.4.10}/comtypes/safearray.py +8 -6
  31. {comtypes-1.4.9 → comtypes-1.4.10}/comtypes/server/__init__.py +22 -4
  32. {comtypes-1.4.9 → comtypes-1.4.10}/comtypes/server/automation.py +1 -2
  33. {comtypes-1.4.9 → comtypes-1.4.10}/comtypes/server/connectionpoints.py +5 -5
  34. {comtypes-1.4.9 → comtypes-1.4.10}/comtypes/server/inprocserver.py +6 -3
  35. {comtypes-1.4.9 → comtypes-1.4.10}/comtypes/server/localserver.py +23 -5
  36. comtypes-1.4.10/comtypes/server/register.py +478 -0
  37. {comtypes-1.4.9 → comtypes-1.4.10}/comtypes/shelllink.py +13 -7
  38. {comtypes-1.4.9 → comtypes-1.4.10}/comtypes/stream.py +7 -4
  39. {comtypes-1.4.9 → comtypes-1.4.10}/comtypes/test/TestComServer.py +6 -7
  40. {comtypes-1.4.9 → comtypes-1.4.10}/comtypes/test/TestDispServer.py +4 -2
  41. {comtypes-1.4.9 → comtypes-1.4.10}/comtypes/test/__init__.py +1 -1
  42. comtypes-1.4.10/comtypes/test/find_memleak.py +72 -0
  43. {comtypes-1.4.9 → comtypes-1.4.10}/comtypes/test/runtests.py +1 -0
  44. {comtypes-1.4.9 → comtypes-1.4.10}/comtypes/test/setup.py +2 -1
  45. {comtypes-1.4.9 → comtypes-1.4.10}/comtypes/test/test_BSTR.py +7 -17
  46. {comtypes-1.4.9 → comtypes-1.4.10}/comtypes/test/test_GUID.py +1 -0
  47. {comtypes-1.4.9 → comtypes-1.4.10}/comtypes/test/test_QueryService.py +1 -0
  48. {comtypes-1.4.9 → comtypes-1.4.10}/comtypes/test/test_agilent.py +4 -3
  49. {comtypes-1.4.9 → comtypes-1.4.10}/comtypes/test/test_basic.py +12 -6
  50. {comtypes-1.4.9 → comtypes-1.4.10}/comtypes/test/test_clear_cache.py +1 -1
  51. {comtypes-1.4.9 → comtypes-1.4.10}/comtypes/test/test_client.py +2 -2
  52. {comtypes-1.4.9 → comtypes-1.4.10}/comtypes/test/test_client_dynamic.py +2 -2
  53. {comtypes-1.4.9 → comtypes-1.4.10}/comtypes/test/test_client_regenerate_modules.py +2 -2
  54. {comtypes-1.4.9 → comtypes-1.4.10}/comtypes/test/test_collections.py +1 -1
  55. {comtypes-1.4.9 → comtypes-1.4.10}/comtypes/test/test_comobject.py +4 -4
  56. {comtypes-1.4.9 → comtypes-1.4.10}/comtypes/test/test_comserver.py +31 -1
  57. {comtypes-1.4.9 → comtypes-1.4.10}/comtypes/test/test_dispifc_records.py +1 -1
  58. {comtypes-1.4.9 → comtypes-1.4.10}/comtypes/test/test_dispifc_safearrays.py +1 -1
  59. {comtypes-1.4.9 → comtypes-1.4.10}/comtypes/test/test_dyndispatch.py +1 -0
  60. {comtypes-1.4.9 → comtypes-1.4.10}/comtypes/test/test_findgendir.py +1 -2
  61. {comtypes-1.4.9 → comtypes-1.4.10}/comtypes/test/test_getactiveobj.py +4 -4
  62. {comtypes-1.4.9 → comtypes-1.4.10}/comtypes/test/test_ie.py +19 -6
  63. {comtypes-1.4.9 → comtypes-1.4.10}/comtypes/test/test_ienum.py +2 -2
  64. {comtypes-1.4.9 → comtypes-1.4.10}/comtypes/test/test_imfattributes.py +13 -3
  65. {comtypes-1.4.9 → comtypes-1.4.10}/comtypes/test/test_inout_args.py +1 -1
  66. {comtypes-1.4.9 → comtypes-1.4.10}/comtypes/test/test_midl_safearray_create.py +6 -4
  67. {comtypes-1.4.9 → comtypes-1.4.10}/comtypes/test/test_monikers.py +23 -9
  68. {comtypes-1.4.9 → comtypes-1.4.10}/comtypes/test/test_msscript.py +2 -1
  69. {comtypes-1.4.9 → comtypes-1.4.10}/comtypes/test/test_npsupport.py +4 -4
  70. {comtypes-1.4.9 → comtypes-1.4.10}/comtypes/test/test_outparam.py +22 -6
  71. {comtypes-1.4.9 → comtypes-1.4.10}/comtypes/test/test_persist.py +2 -4
  72. {comtypes-1.4.9 → comtypes-1.4.10}/comtypes/test/test_recordinfo.py +1 -1
  73. {comtypes-1.4.9 → comtypes-1.4.10}/comtypes/test/test_sapi.py +4 -1
  74. {comtypes-1.4.9 → comtypes-1.4.10}/comtypes/test/test_server_register.py +113 -125
  75. {comtypes-1.4.9 → comtypes-1.4.10}/comtypes/test/test_shelllink.py +2 -3
  76. {comtypes-1.4.9 → comtypes-1.4.10}/comtypes/test/test_storage.py +12 -6
  77. {comtypes-1.4.9 → comtypes-1.4.10}/comtypes/test/test_stream.py +16 -5
  78. {comtypes-1.4.9 → comtypes-1.4.10}/comtypes/test/test_subinterface.py +4 -2
  79. {comtypes-1.4.9 → comtypes-1.4.10}/comtypes/test/test_typeannotator.py +1 -2
  80. {comtypes-1.4.9 → comtypes-1.4.10}/comtypes/test/test_typeinfo.py +19 -7
  81. {comtypes-1.4.9 → comtypes-1.4.10}/comtypes/test/test_urlhistory.py +7 -4
  82. {comtypes-1.4.9 → comtypes-1.4.10}/comtypes/test/test_variant.py +3 -2
  83. {comtypes-1.4.9 → comtypes-1.4.10}/comtypes/test/test_word.py +1 -1
  84. {comtypes-1.4.9 → comtypes-1.4.10}/comtypes/tools/codegenerator/codegenerator.py +167 -435
  85. comtypes-1.4.10/comtypes/tools/codegenerator/comments.py +79 -0
  86. comtypes-1.4.10/comtypes/tools/codegenerator/heads.py +192 -0
  87. {comtypes-1.4.9 → comtypes-1.4.10}/comtypes/tools/codegenerator/helpers.py +3 -6
  88. {comtypes-1.4.9 → comtypes-1.4.10}/comtypes/tools/codegenerator/namespaces.py +13 -5
  89. {comtypes-1.4.9 → comtypes-1.4.10}/comtypes/tools/codegenerator/typeannotator.py +13 -3
  90. {comtypes-1.4.9 → comtypes-1.4.10}/comtypes/tools/tlbparser.py +22 -23
  91. {comtypes-1.4.9 → comtypes-1.4.10}/comtypes/tools/typedesc.py +3 -2
  92. {comtypes-1.4.9 → comtypes-1.4.10}/comtypes/tools/typedesc_base.py +2 -2
  93. {comtypes-1.4.9 → comtypes-1.4.10}/comtypes/typeinfo.py +149 -42
  94. {comtypes-1.4.9 → comtypes-1.4.10}/comtypes/viewobject.py +2 -4
  95. {comtypes-1.4.9 → comtypes-1.4.10/comtypes.egg-info}/PKG-INFO +3 -2
  96. {comtypes-1.4.9 → comtypes-1.4.10}/comtypes.egg-info/SOURCES.txt +5 -0
  97. {comtypes-1.4.9 → comtypes-1.4.10}/pyproject.toml +11 -19
  98. comtypes-1.4.9/comtypes/client/__init__.py +0 -323
  99. comtypes-1.4.9/comtypes/server/register.py +0 -419
  100. comtypes-1.4.9/comtypes/test/find_memleak.py +0 -76
  101. {comtypes-1.4.9 → comtypes-1.4.10}/LICENSE.txt +0 -0
  102. {comtypes-1.4.9 → comtypes-1.4.10}/MANIFEST.in +0 -0
  103. {comtypes-1.4.9 → comtypes-1.4.10}/README.md +0 -0
  104. {comtypes-1.4.9 → comtypes-1.4.10}/comtypes/_npsupport.py +0 -0
  105. {comtypes-1.4.9 → comtypes-1.4.10}/comtypes/_post_coinit/__init__.py +0 -0
  106. {comtypes-1.4.9 → comtypes-1.4.10}/comtypes/_tlib_version_checker.py +0 -0
  107. {comtypes-1.4.9 → comtypes-1.4.10}/comtypes/_vtbl.py +0 -0
  108. {comtypes-1.4.9 → comtypes-1.4.10}/comtypes/clear_cache.py +0 -0
  109. {comtypes-1.4.9 → comtypes-1.4.10}/comtypes/client/_constants.py +0 -0
  110. {comtypes-1.4.9 → comtypes-1.4.10}/comtypes/hints.pyi +0 -0
  111. {comtypes-1.4.9 → comtypes-1.4.10}/comtypes/hresult.py +0 -0
  112. {comtypes-1.4.9 → comtypes-1.4.10}/comtypes/patcher.py +0 -0
  113. {comtypes-1.4.9 → comtypes-1.4.10}/comtypes/server/w_getopt.py +0 -0
  114. {comtypes-1.4.9 → comtypes-1.4.10}/comtypes/test/TestComServer.idl +0 -0
  115. {comtypes-1.4.9 → comtypes-1.4.10}/comtypes/test/TestComServer.tlb +0 -0
  116. {comtypes-1.4.9 → comtypes-1.4.10}/comtypes/test/TestDispServer.idl +0 -0
  117. {comtypes-1.4.9 → comtypes-1.4.10}/comtypes/test/TestDispServer.tlb +0 -0
  118. {comtypes-1.4.9 → comtypes-1.4.10}/comtypes/test/mylib.idl +0 -0
  119. {comtypes-1.4.9 → comtypes-1.4.10}/comtypes/test/mylib.tlb +0 -0
  120. {comtypes-1.4.9 → comtypes-1.4.10}/comtypes/test/mytypelib.idl +0 -0
  121. {comtypes-1.4.9 → comtypes-1.4.10}/comtypes/test/test_DISPPARAMS.py +0 -0
  122. {comtypes-1.4.9 → comtypes-1.4.10}/comtypes/test/test_avmc.py +0 -0
  123. {comtypes-1.4.9 → comtypes-1.4.10}/comtypes/test/test_casesensitivity.py +0 -0
  124. {comtypes-1.4.9 → comtypes-1.4.10}/comtypes/test/test_createwrappers.py +0 -0
  125. {comtypes-1.4.9 → comtypes-1.4.10}/comtypes/test/test_dict.py +0 -0
  126. {comtypes-1.4.9 → comtypes-1.4.10}/comtypes/test/test_dispinterface.py +0 -0
  127. {comtypes-1.4.9 → comtypes-1.4.10}/comtypes/test/test_excel.py +0 -0
  128. {comtypes-1.4.9 → comtypes-1.4.10}/comtypes/test/test_jscript.js +0 -0
  129. {comtypes-1.4.9 → comtypes-1.4.10}/comtypes/test/test_pump_events.py +0 -0
  130. {comtypes-1.4.9 → comtypes-1.4.10}/comtypes/test/test_safearray.py +0 -0
  131. {comtypes-1.4.9 → comtypes-1.4.10}/comtypes/test/test_server.py +0 -0
  132. {comtypes-1.4.9 → comtypes-1.4.10}/comtypes/test/test_showevents.py +0 -0
  133. {comtypes-1.4.9 → comtypes-1.4.10}/comtypes/test/test_w_getopt.py +0 -0
  134. {comtypes-1.4.9 → comtypes-1.4.10}/comtypes/test/test_win32com_interop.py +0 -0
  135. {comtypes-1.4.9 → comtypes-1.4.10}/comtypes/test/test_wmi.py +0 -0
  136. {comtypes-1.4.9 → comtypes-1.4.10}/comtypes/test/urlhist.tlb +0 -0
  137. {comtypes-1.4.9 → comtypes-1.4.10}/comtypes/tools/__init__.py +0 -0
  138. {comtypes-1.4.9 → comtypes-1.4.10}/comtypes/tools/codegenerator/__init__.py +0 -0
  139. {comtypes-1.4.9 → comtypes-1.4.10}/comtypes/tools/codegenerator/modulenamer.py +0 -0
  140. {comtypes-1.4.9 → comtypes-1.4.10}/comtypes/tools/codegenerator/packing.py +0 -0
  141. {comtypes-1.4.9 → comtypes-1.4.10}/comtypes/util.py +0 -0
  142. {comtypes-1.4.9 → comtypes-1.4.10}/comtypes.egg-info/dependency_links.txt +0 -0
  143. {comtypes-1.4.9 → comtypes-1.4.10}/comtypes.egg-info/entry_points.txt +0 -0
  144. {comtypes-1.4.9 → comtypes-1.4.10}/comtypes.egg-info/top_level.txt +0 -0
  145. {comtypes-1.4.9 → comtypes-1.4.10}/setup.cfg +0 -0
  146. {comtypes-1.4.9 → comtypes-1.4.10}/setup.py +0 -0
@@ -0,0 +1,42 @@
1
+ """comtypes.client - High level client level COM support package."""
2
+
3
+ import ctypes
4
+ import logging
5
+
6
+ from comtypes import automation
7
+ from comtypes.client import dynamic, lazybind # noqa
8
+ from comtypes.client._code_cache import _find_gen_dir
9
+ from comtypes.client._constants import Constants # noqa
10
+ from comtypes.client._events import GetEvents, PumpEvents, ShowEvents
11
+ from comtypes.client._generate import GetModule
12
+ from comtypes.client._managing import GetBestInterface, _manage, wrap_outparam # noqa
13
+ from comtypes.hresult import * # noqa
14
+
15
+ gen_dir = _find_gen_dir()
16
+ import comtypes.gen # noqa
17
+
18
+ ### for testing
19
+ ##gen_dir = None
20
+
21
+ logger = logging.getLogger(__name__)
22
+
23
+
24
+ # backwards compatibility:
25
+ wrap = GetBestInterface
26
+
27
+ # Should we do this for POINTER(IUnknown) also?
28
+ ctypes.POINTER(automation.IDispatch).__ctypes_from_outparam__ = wrap_outparam # type: ignore
29
+
30
+ from comtypes.client._activeobj import GetActiveObject
31
+ from comtypes.client._create import (
32
+ CoGetObject,
33
+ CreateObject,
34
+ GetClassObject,
35
+ )
36
+
37
+ # fmt: off
38
+ __all__ = [
39
+ "CreateObject", "GetActiveObject", "CoGetObject", "GetEvents",
40
+ "ShowEvents", "PumpEvents", "GetModule", "GetClassObject",
41
+ ]
42
+ # fmt: on
@@ -0,0 +1,46 @@
1
+ from typing import Any, Optional, Type, TypeVar, overload
2
+ from typing import Union as _UnionT
3
+
4
+ import comtypes
5
+ import comtypes.client.dynamic
6
+ from comtypes import GUID, CoClass, IUnknown, automation
7
+ from comtypes.client._managing import _manage
8
+
9
+ _T_IUnknown = TypeVar("_T_IUnknown", bound=IUnknown)
10
+
11
+
12
+ ################################################################
13
+ #
14
+ # Object creation
15
+ #
16
+ @overload
17
+ def GetActiveObject(progid: _UnionT[str, Type[CoClass], GUID]) -> Any: ...
18
+ @overload
19
+ def GetActiveObject(
20
+ progid: _UnionT[str, Type[CoClass], GUID], interface: Type[_T_IUnknown]
21
+ ) -> _T_IUnknown: ...
22
+ def GetActiveObject(
23
+ progid: _UnionT[str, Type[CoClass], GUID],
24
+ interface: Optional[Type[IUnknown]] = None,
25
+ dynamic: bool = False,
26
+ ) -> Any:
27
+ """Return a pointer to a running COM object that has been
28
+ registered with COM.
29
+
30
+ 'progid' may be a string like "Excel.Application",
31
+ a string specifying a clsid, a GUID instance, or an object with
32
+ a _clsid_ attribute which should be any of the above.
33
+ 'interface' allows to force a certain interface.
34
+ 'dynamic=True' will return a dynamic dispatch object.
35
+ """
36
+ clsid = GUID.from_progid(progid)
37
+ if dynamic:
38
+ if interface is not None:
39
+ raise ValueError("interface and dynamic are mutually exclusive")
40
+ interface = automation.IDispatch
41
+ elif interface is None:
42
+ interface = getattr(progid, "_com_interfaces_", [None])[0]
43
+ obj = comtypes.GetActiveObject(clsid, interface=interface)
44
+ if dynamic:
45
+ return comtypes.client.dynamic.Dispatch(obj)
46
+ return _manage(obj, clsid, interface=interface)
@@ -5,7 +5,12 @@ 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
+ import ctypes
9
+ import logging
10
+ import os
11
+ import sys
12
+ import tempfile
13
+ import types
9
14
  from ctypes import wintypes
10
15
 
11
16
  logger = logging.getLogger(__name__)
@@ -0,0 +1,147 @@
1
+ import logging
2
+ from typing import TYPE_CHECKING, Any, Optional, Type, TypeVar, overload
3
+ from typing import Union as _UnionT
4
+
5
+ import comtypes
6
+ import comtypes.client.dynamic
7
+ from comtypes import COSERVERINFO, GUID, CoClass, IUnknown, automation
8
+ from comtypes.client._managing import _manage
9
+
10
+ if TYPE_CHECKING:
11
+ from comtypes import hints # type: ignore
12
+
13
+
14
+ _T_IUnknown = TypeVar("_T_IUnknown", bound=IUnknown)
15
+ logger = logging.getLogger(__name__)
16
+
17
+
18
+ ################################################################
19
+ #
20
+ # Object creation
21
+ #
22
+ if TYPE_CHECKING:
23
+
24
+ @overload
25
+ def GetClassObject(
26
+ progid: _UnionT[str, Type[CoClass], GUID],
27
+ clsctx: Optional[int] = None,
28
+ pServerInfo: Optional[COSERVERINFO] = None,
29
+ interface: None = None,
30
+ ) -> hints.IClassFactory: ...
31
+ @overload
32
+ def GetClassObject(
33
+ progid: _UnionT[str, Type[CoClass], GUID],
34
+ clsctx: Optional[int] = None,
35
+ pServerInfo: Optional[COSERVERINFO] = None,
36
+ interface: Type[_T_IUnknown] = hints.IClassFactory,
37
+ ) -> _T_IUnknown: ...
38
+
39
+
40
+ def GetClassObject(progid, clsctx=None, pServerInfo=None, interface=None):
41
+ # type: (_UnionT[str, Type[CoClass], GUID], Optional[int], Optional[COSERVERINFO], Optional[Type[IUnknown]]) -> IUnknown
42
+ """Create and return the class factory for a COM object.
43
+
44
+ 'clsctx' specifies how to create the object, use the CLSCTX_... constants.
45
+ 'pServerInfo', if used, must be a pointer to a comtypes.COSERVERINFO instance
46
+ 'interface' may be used to request an interface other than IClassFactory
47
+ """
48
+ clsid = GUID.from_progid(progid)
49
+ return comtypes.CoGetClassObject(clsid, clsctx, pServerInfo, interface)
50
+
51
+
52
+ @overload
53
+ def CreateObject(progid: _UnionT[str, Type[CoClass], GUID]) -> Any: ...
54
+ @overload
55
+ def CreateObject(
56
+ progid: _UnionT[str, Type[CoClass], GUID],
57
+ clsctx: Optional[int] = None,
58
+ machine: Optional[str] = None,
59
+ interface: Optional[Type[_T_IUnknown]] = None,
60
+ dynamic: bool = ...,
61
+ pServerInfo: Optional[COSERVERINFO] = None,
62
+ ) -> _T_IUnknown: ...
63
+ def CreateObject(
64
+ progid: _UnionT[str, Type[CoClass], GUID], # which object to create
65
+ clsctx: Optional[int] = None, # how to create the object
66
+ machine: Optional[str] = None, # where to create the object
67
+ interface: Optional[Type[IUnknown]] = None, # the interface we want
68
+ dynamic: bool = False, # use dynamic dispatch
69
+ pServerInfo: Optional[COSERVERINFO] = None, # server info struct for remoting
70
+ ) -> Any:
71
+ """Create a COM object from 'progid', and try to QueryInterface()
72
+ it to the most useful interface, generating typelib support on
73
+ demand. A pointer to this interface is returned.
74
+
75
+ 'progid' may be a string like "InternetExplorer.Application",
76
+ a string specifying a clsid, a GUID instance, or an object with
77
+ a _clsid_ attribute which should be any of the above.
78
+ 'clsctx' specifies how to create the object, use the CLSCTX_... constants.
79
+ 'machine' allows to specify a remote machine to create the object on.
80
+ 'interface' allows to force a certain interface
81
+ 'dynamic=True' will return a dynamic dispatch object
82
+ 'pServerInfo', if used, must be a pointer to a comtypes.COSERVERINFO instance
83
+ This supercedes 'machine'.
84
+
85
+ You can also later request to receive events with GetEvents().
86
+ """
87
+ clsid = GUID.from_progid(progid)
88
+ logger.debug("%s -> %s", progid, clsid)
89
+ if dynamic:
90
+ if interface:
91
+ raise ValueError("interface and dynamic are mutually exclusive")
92
+ interface = automation.IDispatch
93
+ elif interface is None:
94
+ interface = getattr(progid, "_com_interfaces_", [None])[0]
95
+ if machine is None and pServerInfo is None:
96
+ logger.debug(
97
+ "CoCreateInstance(%s, clsctx=%s, interface=%s)", clsid, clsctx, interface
98
+ )
99
+ obj = comtypes.CoCreateInstance(clsid, clsctx=clsctx, interface=interface)
100
+ else:
101
+ logger.debug(
102
+ "CoCreateInstanceEx(%s, clsctx=%s, interface=%s, machine=%s,\
103
+ pServerInfo=%s)",
104
+ clsid,
105
+ clsctx,
106
+ interface,
107
+ machine,
108
+ pServerInfo,
109
+ )
110
+ if machine is not None and pServerInfo is not None:
111
+ msg = "You cannot set both the machine name and server info."
112
+ raise ValueError(msg)
113
+ obj = comtypes.CoCreateInstanceEx(
114
+ clsid,
115
+ clsctx=clsctx,
116
+ interface=interface,
117
+ machine=machine,
118
+ pServerInfo=pServerInfo,
119
+ )
120
+ if dynamic:
121
+ return comtypes.client.dynamic.Dispatch(obj)
122
+ return _manage(obj, clsid, interface=interface)
123
+
124
+
125
+ @overload
126
+ def CoGetObject(displayname: str, interface: Type[_T_IUnknown]) -> _T_IUnknown: ...
127
+ @overload
128
+ def CoGetObject(
129
+ displayname: str, interface: None = None, dynamic: bool = False
130
+ ) -> Any: ...
131
+ def CoGetObject(
132
+ displayname: str,
133
+ interface: Optional[Type[IUnknown]] = None,
134
+ dynamic: bool = False,
135
+ ) -> Any:
136
+ """Create an object by calling CoGetObject(displayname).
137
+
138
+ Additional parameters have the same meaning as in CreateObject().
139
+ """
140
+ if dynamic:
141
+ if interface is not None:
142
+ raise ValueError("interface and dynamic are mutually exclusive")
143
+ interface = automation.IDispatch
144
+ punk = comtypes.CoGetObject(displayname, interface)
145
+ if dynamic:
146
+ return comtypes.client.dynamic.Dispatch(punk)
147
+ return _manage(punk, clsid=None, interface=interface)
@@ -1,16 +1,63 @@
1
1
  import ctypes
2
+ import logging
2
3
  import traceback
4
+ from ctypes import HRESULT, POINTER, WINFUNCTYPE, OleDLL, Structure, WinDLL
5
+ from ctypes.wintypes import (
6
+ BOOL,
7
+ DWORD,
8
+ HANDLE,
9
+ LPCSTR,
10
+ LPDWORD,
11
+ LPHANDLE,
12
+ LPVOID,
13
+ ULONG,
14
+ )
15
+
3
16
  import comtypes
4
- import comtypes.hresult
5
17
  import comtypes.automation
6
- import comtypes.typeinfo
7
18
  import comtypes.connectionpoints
19
+ import comtypes.hresult
20
+ import comtypes.typeinfo
8
21
  from comtypes.client._generate import GetModule
9
- import logging
10
22
 
11
23
  logger = logging.getLogger(__name__)
12
24
 
13
25
 
26
+ class SECURITY_ATTRIBUTES(Structure):
27
+ _fields_ = [
28
+ ("nLength", DWORD),
29
+ ("lpSecurityDescriptor", LPVOID),
30
+ ("bInheritHandle", BOOL),
31
+ ]
32
+
33
+
34
+ _ole32 = OleDLL("ole32")
35
+
36
+ _CoWaitForMultipleHandles = _ole32.CoWaitForMultipleHandles
37
+ _CoWaitForMultipleHandles.argtypes = [DWORD, DWORD, ULONG, LPHANDLE, LPDWORD]
38
+ _CoWaitForMultipleHandles.restype = HRESULT
39
+
40
+
41
+ _kernel32 = WinDLL("kernel32")
42
+
43
+ _CreateEventA = _kernel32.CreateEventA
44
+ _CreateEventA.argtypes = [POINTER(SECURITY_ATTRIBUTES), BOOL, BOOL, LPCSTR]
45
+ _CreateEventA.restype = HANDLE
46
+
47
+ _SetEvent = _kernel32.SetEvent
48
+ _SetEvent.argtypes = [HANDLE]
49
+ _SetEvent.restype = BOOL
50
+
51
+ PHANDLER_ROUTINE = WINFUNCTYPE(BOOL, DWORD)
52
+ _SetConsoleCtrlHandler = _kernel32.SetConsoleCtrlHandler
53
+ _SetConsoleCtrlHandler.argtypes = [PHANDLER_ROUTINE, BOOL]
54
+ _SetConsoleCtrlHandler.restype = BOOL
55
+
56
+ _CloseHandle = _kernel32.CloseHandle
57
+ _CloseHandle.argtypes = [HANDLE]
58
+ _CloseHandle.restype = BOOL
59
+
60
+
14
61
  class _AdviseConnection(object):
15
62
  def __init__(self, source, interface, receiver):
16
63
  self.cp = None
@@ -274,24 +321,22 @@ def PumpEvents(timeout):
274
321
  # CoWaitForMultipleHandles calls the Win32 function
275
322
  # MsgWaitForMultipleObjects.
276
323
 
277
- hevt = ctypes.windll.kernel32.CreateEventA(None, True, False, None)
324
+ hevt = _CreateEventA(None, True, False, None)
278
325
  handles = _handles_type(hevt)
279
326
  RPC_S_CALLPENDING = -2147417835
280
327
 
281
- # @ctypes.WINFUNCTYPE(ctypes.c_int, ctypes.c_uint)
328
+ # @ctypes.WINFUNCTYPE(BOOL, DWORD)
282
329
  def HandlerRoutine(dwCtrlType):
283
330
  if dwCtrlType == 0: # CTRL+C
284
- ctypes.windll.kernel32.SetEvent(hevt)
331
+ _SetEvent(hevt)
285
332
  return 1
286
333
  return 0
287
334
 
288
- HandlerRoutine = ctypes.WINFUNCTYPE(ctypes.c_int, ctypes.c_uint)(HandlerRoutine)
289
-
290
- ctypes.windll.kernel32.SetConsoleCtrlHandler(HandlerRoutine, 1)
335
+ _SetConsoleCtrlHandler(PHANDLER_ROUTINE(HandlerRoutine), 1)
291
336
 
292
337
  try:
293
338
  try:
294
- res = ctypes.oledll.ole32.CoWaitForMultipleHandles(
339
+ res = _CoWaitForMultipleHandles(
295
340
  0,
296
341
  int(timeout * 1000),
297
342
  len(handles),
@@ -304,5 +349,5 @@ def PumpEvents(timeout):
304
349
  else:
305
350
  raise KeyboardInterrupt
306
351
  finally:
307
- ctypes.windll.kernel32.CloseHandle(hevt)
308
- ctypes.windll.kernel32.SetConsoleCtrlHandler(HandlerRoutine, 0)
352
+ _CloseHandle(hevt)
353
+ _SetConsoleCtrlHandler(PHANDLER_ROUTINE(HandlerRoutine), 0)
@@ -5,14 +5,14 @@ import logging
5
5
  import os
6
6
  import sys
7
7
  import types
8
- from typing import Any, Tuple, List, Mapping, Optional, Dict, Union as _UnionT
9
8
  import winreg
9
+ from typing import Any, Dict, List, Mapping, Optional, Tuple
10
+ from typing import Union as _UnionT
10
11
 
11
- from comtypes import GUID, typeinfo
12
12
  import comtypes.client
13
+ from comtypes import GUID, typeinfo
13
14
  from comtypes.tools import codegenerator, tlbparser
14
15
 
15
-
16
16
  logger = logging.getLogger(__name__)
17
17
 
18
18
  PATH = os.environ["PATH"].split(os.pathsep)
@@ -0,0 +1,114 @@
1
+ import logging
2
+ from _ctypes import COMError
3
+ from typing import Any, Optional, Type
4
+
5
+ import comtypes
6
+ import comtypes.client.dynamic
7
+ from comtypes import GUID, IUnknown, automation, typeinfo
8
+ from comtypes.client._generate import GetModule
9
+
10
+ logger = logging.getLogger(__name__)
11
+
12
+
13
+ def wrap_outparam(punk: Any) -> Any:
14
+ logger.debug("wrap_outparam(%s)", punk)
15
+ if not punk:
16
+ return None
17
+ if punk.__com_interface__ == automation.IDispatch:
18
+ return GetBestInterface(punk)
19
+ return punk
20
+
21
+
22
+ def GetBestInterface(punk: Any) -> Any:
23
+ """Try to QueryInterface a COM pointer to the 'most useful'
24
+ interface.
25
+
26
+ Get type information for the provided object, either via
27
+ IDispatch.GetTypeInfo(), or via IProvideClassInfo.GetClassInfo().
28
+ Generate a wrapper module for the typelib, and QI for the
29
+ interface found.
30
+ """
31
+ if not punk: # NULL COM pointer
32
+ return punk # or should we return None?
33
+ # find the typelib and the interface name
34
+ logger.debug("GetBestInterface(%s)", punk)
35
+ try:
36
+ try:
37
+ pci = punk.QueryInterface(typeinfo.IProvideClassInfo)
38
+ logger.debug("Does implement IProvideClassInfo")
39
+ except COMError:
40
+ # Some COM objects support IProvideClassInfo2, but not IProvideClassInfo.
41
+ # These objects are broken, but we support them anyway.
42
+ logger.debug(
43
+ "Does NOT implement IProvideClassInfo, trying IProvideClassInfo2"
44
+ )
45
+ pci = punk.QueryInterface(typeinfo.IProvideClassInfo2)
46
+ logger.debug("Does implement IProvideClassInfo2")
47
+ tinfo = pci.GetClassInfo() # TypeInfo for the CoClass
48
+ # find the interface marked as default
49
+ ta = tinfo.GetTypeAttr()
50
+ for index in range(ta.cImplTypes):
51
+ if tinfo.GetImplTypeFlags(index) == 1:
52
+ break
53
+ else:
54
+ if ta.cImplTypes != 1:
55
+ # Hm, should we use dynamic now?
56
+ raise TypeError("No default interface found")
57
+ # Only one interface implemented, use that (even if
58
+ # not marked as default).
59
+ index = 0
60
+ href = tinfo.GetRefTypeOfImplType(index)
61
+ tinfo = tinfo.GetRefTypeInfo(href)
62
+ except COMError:
63
+ logger.debug("Does NOT implement IProvideClassInfo/IProvideClassInfo2")
64
+ try:
65
+ pdisp = punk.QueryInterface(automation.IDispatch)
66
+ except COMError:
67
+ logger.debug("No Dispatch interface: %s", punk)
68
+ return punk
69
+ try:
70
+ tinfo = pdisp.GetTypeInfo(0)
71
+ except COMError:
72
+ pdisp = comtypes.client.dynamic.Dispatch(pdisp)
73
+ logger.debug("IDispatch.GetTypeInfo(0) failed: %s" % pdisp)
74
+ return pdisp
75
+ typeattr = tinfo.GetTypeAttr()
76
+ logger.debug("Default interface is %s", typeattr.guid)
77
+ try:
78
+ punk.QueryInterface(IUnknown, typeattr.guid)
79
+ except COMError:
80
+ logger.debug("Does not implement default interface, returning dynamic object")
81
+ return comtypes.client.dynamic.Dispatch(punk)
82
+
83
+ itf_name = tinfo.GetDocumentation(-1)[0] # interface name
84
+ tlib = tinfo.GetContainingTypeLib()[0] # typelib
85
+
86
+ # import the wrapper, generating it on demand
87
+ mod = GetModule(tlib)
88
+ # Python interface class
89
+ interface = getattr(mod, itf_name)
90
+ logger.debug("Implements default interface from typeinfo %s", interface)
91
+ # QI for this interface
92
+ # XXX
93
+ # What to do if this fails?
94
+ # In the following example the engine.Eval() call returns
95
+ # such an object.
96
+ #
97
+ # engine = CreateObject("MsScriptControl.ScriptControl")
98
+ # engine.Language = "JScript"
99
+ # engine.Eval("[1, 2, 3]")
100
+ #
101
+ # Could the above code, as an optimization, check that QI works,
102
+ # *before* generating the wrapper module?
103
+ result = punk.QueryInterface(interface)
104
+ logger.debug("Final result is %s", result)
105
+ return result
106
+
107
+
108
+ def _manage(
109
+ obj: Any, clsid: Optional[GUID], interface: Optional[Type[IUnknown]]
110
+ ) -> Any:
111
+ obj.__dict__["__clsid"] = str(clsid)
112
+ if interface is None:
113
+ obj = GetBestInterface(obj)
114
+ return obj
@@ -1,10 +1,9 @@
1
1
  import ctypes
2
2
  from typing import Any, Dict, Optional, Set, Type, TypeVar
3
3
 
4
- from comtypes import automation
4
+ from comtypes import GUID, COMError, IUnknown, _is_object, automation
5
+ from comtypes import hresult as hres
5
6
  from comtypes.client import lazybind
6
- from comtypes import COMError, GUID, IUnknown, hresult as hres, _is_object
7
-
8
7
 
9
8
  _T_IUnknown = TypeVar("_T_IUnknown", bound=IUnknown)
10
9
  # These errors generally mean the property or method exists,
@@ -1,16 +1,15 @@
1
1
  import comtypes
2
2
  import comtypes.automation
3
-
4
- from comtypes.automation import IEnumVARIANT
5
- from comtypes.automation import DISPATCH_METHOD
6
- from comtypes.automation import DISPATCH_PROPERTYGET
7
- from comtypes.automation import DISPATCH_PROPERTYPUT
8
- from comtypes.automation import DISPATCH_PROPERTYPUTREF
9
-
10
- from comtypes.automation import DISPID_VALUE
11
- from comtypes.automation import DISPID_NEWENUM
12
-
13
- from comtypes.typeinfo import FUNC_PUREVIRTUAL, FUNC_DISPATCH
3
+ from comtypes.automation import (
4
+ DISPATCH_METHOD,
5
+ DISPATCH_PROPERTYGET,
6
+ DISPATCH_PROPERTYPUT,
7
+ DISPATCH_PROPERTYPUTREF,
8
+ DISPID_NEWENUM,
9
+ DISPID_VALUE,
10
+ IEnumVARIANT,
11
+ )
12
+ from comtypes.typeinfo import FUNC_DISPATCH, FUNC_PUREVIRTUAL
14
13
 
15
14
 
16
15
  class FuncDesc(object):
@@ -1,6 +1,7 @@
1
1
  import sys
2
2
  from ctypes import *
3
- from comtypes import IUnknown, COMMETHOD, GUID, HRESULT, dispid
3
+
4
+ from comtypes import COMMETHOD, GUID, HRESULT, IUnknown, dispid
4
5
 
5
6
  _GUID = GUID
6
7
 
@@ -1,7 +1,8 @@
1
1
  import sys
2
2
  from ctypes import *
3
- from ctypes.wintypes import DWORD
4
- from comtypes import IUnknown, HRESULT, COMMETHOD, GUID, BSTR
3
+ from ctypes.wintypes import DWORD, ULONG
4
+
5
+ from comtypes import BSTR, COMMETHOD, GUID, HRESULT, IUnknown
5
6
  from comtypes.hresult import *
6
7
 
7
8
  LPCOLESTR = c_wchar_p
@@ -45,26 +46,38 @@ class ISupportErrorInfo(IUnknown):
45
46
 
46
47
 
47
48
  ################################################################
48
- _oleaut32 = oledll.oleaut32
49
+ _oleaut32 = OleDLL("oleaut32")
50
+
51
+ _CreateErrorInfo = _oleaut32.CreateErrorInfo
52
+ _CreateErrorInfo.argtypes = [POINTER(POINTER(ICreateErrorInfo))]
53
+ _CreateErrorInfo.restype = HRESULT
54
+
55
+ _GetErrorInfo = _oleaut32.GetErrorInfo
56
+ _GetErrorInfo.argtypes = [ULONG, POINTER(POINTER(IErrorInfo))]
57
+ _GetErrorInfo.restype = HRESULT
58
+
59
+ _SetErrorInfo = _oleaut32.SetErrorInfo
60
+ _SetErrorInfo.argtypes = [ULONG, POINTER(IErrorInfo)]
61
+ _SetErrorInfo.restype = HRESULT
49
62
 
50
63
 
51
64
  def CreateErrorInfo():
52
65
  cei = POINTER(ICreateErrorInfo)()
53
- _oleaut32.CreateErrorInfo(byref(cei))
66
+ _CreateErrorInfo(byref(cei))
54
67
  return cei
55
68
 
56
69
 
57
70
  def GetErrorInfo():
58
71
  """Get the error information for the current thread."""
59
72
  errinfo = POINTER(IErrorInfo)()
60
- if S_OK == _oleaut32.GetErrorInfo(0, byref(errinfo)):
73
+ if S_OK == _GetErrorInfo(0, byref(errinfo)):
61
74
  return errinfo
62
75
  return None
63
76
 
64
77
 
65
78
  def SetErrorInfo(errinfo):
66
79
  """Set error information for the current thread."""
67
- return _oleaut32.SetErrorInfo(0, errinfo)
80
+ return _SetErrorInfo(0, errinfo)
68
81
 
69
82
 
70
83
  def ReportError(
@@ -89,7 +102,7 @@ def ReportError(
89
102
  ei.SetSource(
90
103
  progid
91
104
  ) # progid for the class or application that created the error
92
- _oleaut32.SetErrorInfo(0, ei)
105
+ _SetErrorInfo(0, ei)
93
106
  return hresult
94
107
 
95
108
 
@@ -6,14 +6,15 @@ between different threading appartments.
6
6
 
7
7
  from ctypes import *
8
8
  from ctypes.wintypes import DWORD
9
+
9
10
  from comtypes import (
10
- IUnknown,
11
- STDMETHOD,
11
+ CLSCTX_INPROC_SERVER,
12
12
  COMMETHOD,
13
13
  GUID,
14
14
  HRESULT,
15
+ STDMETHOD,
15
16
  CoCreateInstance,
16
- CLSCTX_INPROC_SERVER,
17
+ IUnknown,
17
18
  )
18
19
 
19
20
 
@@ -1,13 +1,25 @@
1
1
  # logutil.py
2
- import logging, ctypes
2
+ import logging
3
+ from ctypes import WinDLL
4
+ from ctypes.wintypes import LPCSTR, LPCWSTR
5
+
6
+ _kernel32 = WinDLL("kernel32")
7
+
8
+ _OutputDebugStringA = _kernel32.OutputDebugStringA
9
+ _OutputDebugStringA.argtypes = [LPCSTR]
10
+ _OutputDebugStringA.restype = None
11
+
12
+ _OutputDebugStringW = _kernel32.OutputDebugStringW
13
+ _OutputDebugStringW.argtypes = [LPCWSTR]
14
+ _OutputDebugStringW.restype = None
3
15
 
4
16
 
5
17
  class NTDebugHandler(logging.Handler):
6
18
  def emit(
7
19
  self,
8
20
  record,
9
- writeA=ctypes.windll.kernel32.OutputDebugStringA,
10
- writeW=ctypes.windll.kernel32.OutputDebugStringW,
21
+ writeA=_OutputDebugStringA,
22
+ writeW=_OutputDebugStringW,
11
23
  ):
12
24
  text = self.format(record)
13
25
  if isinstance(text, str):
@@ -1,5 +1,5 @@
1
1
  import ctypes
2
- from ctypes import WinDLL, byref, WinError
2
+ from ctypes import WinDLL, WinError, byref
3
3
  from ctypes.wintypes import MSG
4
4
 
5
5
  _user32 = WinDLL("user32")
@@ -10,13 +10,11 @@ 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
14
- from ctypes import POINTER, Structure
15
- from ctypes.wintypes import WORD, DWORD, BOOL
13
+ from ctypes import POINTER, Structure, c_int, c_ulong, c_ushort, c_wchar_p
14
+ from ctypes.wintypes import BOOL, DWORD, WORD
16
15
  from typing import TYPE_CHECKING
17
16
 
18
- from comtypes import GUID, IUnknown, COMMETHOD, HRESULT
19
- from comtypes import IPersist
17
+ from comtypes import COMMETHOD, GUID, HRESULT, IPersist, IUnknown
20
18
  from comtypes.automation import VARIANT, tagEXCEPINFO
21
19
 
22
20
  if TYPE_CHECKING: