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
@@ -1,6 +1,25 @@
1
1
  Comtypes CHANGELOG
2
2
  ==================
3
3
 
4
+ Release 1.4.10
5
+ --------------
6
+ * Replace ``GetModuleFileNameA`` with ``GetModuleFileNameW`` to prevent a ``TypeError``. By @junkmd.
7
+ * Refactor ``server.register``. By @junkmd.
8
+ * ``PythonClass`` and ``PythonPath`` are no longer registered in the registry for a frozen server. By @junkmd.
9
+ * Use ``WinDLL``/``OleDLL`` instead of ``windll``/``oledll``. By @moi15moi.
10
+ * In ``tools.tlbparser``, replace ``windll.oleaut32.QueryPathOfRegTypeLib`` with ``typeinfo.QueryPathOfRegTypeLib``. By @moi15moi.
11
+ * Adjust ``QueryPathOfRegTypeLib`` docstring. By @moi15moi.
12
+ * Reserve blank lines in the generated modules. By @junkmd.
13
+ * Refactor ``tools`` subpackage. By @junkmd.
14
+ * Add ``ActiveObjTest`` to ``test_comserver``. By @junkmd.
15
+ * Replace deprecated install command in CI pipelines. By @moi15moi.
16
+ * Remove unused parameters in ``_shutdown``. By @moi15moi.
17
+ * Delete ``preview.bat``. By @moi15moi.
18
+ * Remove unnecessary ``ruff`` lint rules from ``pyproject.toml``. By @moi15moi.
19
+ * Refactor some code from ``client/__init__.py`` into modules. By @junkmd.
20
+ * Remove workarounds for Windows CE in ``find_memleak``. By @junkmd.
21
+ * Format import blocks and add ``extend-select = ["I"]`` to ``[tool.ruff.lint]``. By @junkmd.
22
+
4
23
  Release 1.4.9
5
24
  --------------
6
25
  * Separate patch processing within ``_com_interface_meta`` into a module. By @junkmd.
@@ -1,6 +1,6 @@
1
- Metadata-Version: 2.1
1
+ Metadata-Version: 2.2
2
2
  Name: comtypes
3
- Version: 1.4.9
3
+ Version: 1.4.10
4
4
  Summary: Pure Python COM package
5
5
  Home-page: https://github.com/enthought/comtypes
6
6
  Download-URL: https://github.com/enthought/comtypes/releases
@@ -16,6 +16,7 @@ Classifier: Topic :: Software Development :: Libraries :: Python Modules
16
16
  Requires-Python: >=3.8
17
17
  Description-Content-Type: text/markdown
18
18
  License-File: LICENSE.txt
19
+ Dynamic: download-url
19
20
 
20
21
  # comtypes
21
22
 
@@ -1,9 +1,8 @@
1
1
  """comtypes.GUID module"""
2
2
 
3
- from ctypes import oledll, windll
4
- from ctypes import byref, c_wchar_p, Structure
5
- from ctypes.wintypes import BYTE, WORD, DWORD
6
- from typing import Any, TYPE_CHECKING
3
+ from ctypes import HRESULT, POINTER, OleDLL, Structure, WinDLL, byref, c_wchar_p
4
+ from ctypes.wintypes import BYTE, DWORD, LPVOID, WORD
5
+ from typing import TYPE_CHECKING, Any
7
6
 
8
7
  if TYPE_CHECKING:
9
8
  from comtypes import hints # type: ignore
@@ -13,15 +12,6 @@ def binary(obj: "GUID") -> bytes:
13
12
  return bytes(obj)
14
13
 
15
14
 
16
- _ole32 = oledll.ole32
17
-
18
- _StringFromCLSID = _ole32.StringFromCLSID
19
- _CoTaskMemFree = windll.ole32.CoTaskMemFree
20
- _ProgIDFromCLSID = _ole32.ProgIDFromCLSID
21
- _CLSIDFromString = _ole32.CLSIDFromString
22
- _CLSIDFromProgID = _ole32.CLSIDFromProgID
23
- _CoCreateGuid = _ole32.CoCreateGuid
24
-
25
15
  # Note: Comparing GUID instances by comparing their buffers
26
16
  # is slightly faster than using ole32.IsEqualGUID.
27
17
 
@@ -93,6 +83,37 @@ class GUID(Structure):
93
83
  return guid
94
84
 
95
85
 
86
+ REFCLSID = POINTER(GUID)
87
+ LPOLESTR = LPCOLESTR = c_wchar_p
88
+ LPCLSID = POINTER(GUID)
89
+
90
+ _ole32_nohresult = WinDLL("ole32")
91
+ _ole32 = OleDLL("ole32")
92
+
93
+ _StringFromCLSID = _ole32.StringFromCLSID
94
+ _StringFromCLSID.argtypes = [REFCLSID, POINTER(LPOLESTR)]
95
+ _StringFromCLSID.restype = HRESULT
96
+
97
+ _CoTaskMemFree = _ole32_nohresult.CoTaskMemFree
98
+ _CoTaskMemFree.argtypes = [LPVOID]
99
+ _CoTaskMemFree.restype = None
100
+
101
+ _ProgIDFromCLSID = _ole32.ProgIDFromCLSID
102
+ _ProgIDFromCLSID.argtypes = [REFCLSID, POINTER(LPOLESTR)]
103
+ _ProgIDFromCLSID.restype = HRESULT
104
+
105
+ _CLSIDFromString = _ole32.CLSIDFromString
106
+ _CLSIDFromString.argtypes = [LPCOLESTR, LPCLSID]
107
+ _CLSIDFromString.restype = HRESULT
108
+
109
+ _CLSIDFromProgID = _ole32.CLSIDFromProgID
110
+ _CLSIDFromProgID.argtypes = [LPCOLESTR, LPCLSID]
111
+ _CLSIDFromProgID.restype = HRESULT
112
+
113
+ _CoCreateGuid = _ole32.CoCreateGuid
114
+ _CoCreateGuid.argtypes = [POINTER(GUID)]
115
+ _CoCreateGuid.restype = HRESULT
116
+
96
117
  GUID_null = GUID()
97
118
 
98
119
  __all__ = ["GUID"]
@@ -1,5 +1,5 @@
1
1
  # comtypes version numbers follow semver (http://semver.org/) and PEP 440
2
- __version__ = "1.4.9"
2
+ __version__ = "1.4.10"
3
3
 
4
4
  try:
5
5
  from _ctypes import COMError # noqa
@@ -15,31 +15,30 @@ except ImportError as e:
15
15
  raise ImportError(msg) from e
16
16
 
17
17
  import atexit
18
+ import logging
19
+ import sys
18
20
 
19
21
  # HACK: Workaround for projects that depend on this package
20
22
  # There should be several projects around the world that depend on this package
21
23
  # and indirectly reference the symbols of `ctypes` from `comtypes`.
22
24
  # If we remove the wildcard import from `ctypes`, they might break. So it is
23
25
  # left in the following line.
24
- from ctypes import * # noqa
25
- from ctypes import HRESULT # noqa
26
- from ctypes import _Pointer, _SimpleCData # noqa
27
- from ctypes import c_int, c_ulong, oledll, windll
28
- from ctypes.wintypes import DWORD # noqa
29
- import logging
30
- import sys
26
+ from ctypes import * # noqa # type: ignore
27
+ from ctypes import HRESULT, OleDLL, WinDLL, _SimpleCData, c_int, c_ulong
28
+ from ctypes.wintypes import DWORD, LPVOID
31
29
  from typing import TYPE_CHECKING
32
30
 
33
31
  if TYPE_CHECKING:
34
32
  from ctypes import _CData # only in `typeshed`, private in runtime
33
+
35
34
  from comtypes import hints as hints # noqa # type: ignore
36
35
  else:
37
36
  _CData = _SimpleCData.__mro__[:-1][-1]
38
37
 
39
- from comtypes.GUID import GUID
40
38
  from comtypes import patcher # noqa
41
39
  from comtypes._npsupport import interop as npsupport # noqa
42
40
  from comtypes._tlib_version_checker import _check_version # noqa
41
+ from comtypes.GUID import GUID
43
42
 
44
43
  _all_slice = slice(None, None, None)
45
44
 
@@ -121,8 +120,18 @@ EOAC_NONE = 0
121
120
 
122
121
  ################################################################
123
122
  # Initialization and shutdown
124
- _ole32 = oledll.ole32
125
- _ole32_nohresult = windll.ole32 # use this for functions that don't return a HRESULT
123
+ _ole32 = OleDLL("ole32")
124
+
125
+ _CoInitializeEx = _ole32.CoInitializeEx
126
+ _CoInitializeEx.argtypes = [LPVOID, DWORD]
127
+ _CoInitializeEx.restype = HRESULT
128
+
129
+ _ole32_nohresult = WinDLL("ole32") # use this for functions that don't return a HRESULT
130
+
131
+ _CoUninitialize = _ole32_nohresult.CoUninitialize
132
+ _CoUninitialize.argtypes = []
133
+ _CoUninitialize.restype = None
134
+
126
135
 
127
136
  COINIT_MULTITHREADED = 0x0
128
137
  COINIT_APARTMENTTHREADED = 0x2
@@ -138,7 +147,7 @@ def CoInitializeEx(flags=None):
138
147
  if flags is None:
139
148
  flags = getattr(sys, "coinit_flags", COINIT_APARTMENTTHREADED)
140
149
  logger.debug("CoInitializeEx(None, %s)", flags)
141
- _ole32.CoInitializeEx(None, flags)
150
+ _CoInitializeEx(None, flags)
142
151
 
143
152
 
144
153
  # COM is initialized automatically for the thread that imports this
@@ -156,7 +165,7 @@ CoInitializeEx()
156
165
  # in which we are using COM
157
166
  def CoUninitialize():
158
167
  logger.debug("CoUninitialize()")
159
- _ole32_nohresult.CoUninitialize()
168
+ _CoUninitialize()
160
169
 
161
170
 
162
171
  ################################################################
@@ -4,14 +4,16 @@ from _ctypes import COMError, CopyComPointer
4
4
  from ctypes import (
5
5
  POINTER,
6
6
  FormatError,
7
+ OleDLL,
7
8
  Structure,
9
+ WinDLL,
8
10
  byref,
9
11
  c_long,
10
12
  c_void_p,
11
- oledll,
13
+ c_wchar_p,
12
14
  pointer,
13
- windll,
14
15
  )
16
+ from ctypes.wintypes import INT, LONG, LPVOID, UINT, ULONG, WORD
15
17
  from typing import (
16
18
  TYPE_CHECKING,
17
19
  Any,
@@ -27,8 +29,9 @@ from typing import (
27
29
  )
28
30
  from typing import Union as _UnionT
29
31
 
30
- from comtypes import GUID, IPersist, IUnknown, hresult
32
+ from comtypes import GUID, IPersist, IUnknown, _CoUninitialize, hresult
31
33
  from comtypes._vtbl import _MethodFinder, create_dispimpl, create_vtbl_mapping
34
+ from comtypes.automation import DISPID, DISPPARAMS, EXCEPINFO, VARIANT
32
35
  from comtypes.errorinfo import ISupportErrorInfo
33
36
  from comtypes.typeinfo import IProvideClassInfo, IProvideClassInfo2, ITypeInfo
34
37
 
@@ -51,9 +54,10 @@ DISPATCH_PROPERTYPUTREF = 8
51
54
 
52
55
  ################################################################
53
56
 
57
+ _kernel32 = WinDLL("kernel32")
54
58
  try:
55
- _InterlockedIncrement = windll.kernel32.InterlockedIncrement
56
- _InterlockedDecrement = windll.kernel32.InterlockedDecrement
59
+ _InterlockedIncrement = _kernel32.InterlockedIncrement
60
+ _InterlockedDecrement = _kernel32.InterlockedDecrement
57
61
  except AttributeError:
58
62
  import threading
59
63
 
@@ -82,14 +86,65 @@ else:
82
86
  _InterlockedIncrement.restype = c_long
83
87
  _InterlockedDecrement.restype = c_long
84
88
 
89
+ _oleaut32 = WinDLL("oleaut32")
90
+
91
+ _DispGetIDsOfNames = _oleaut32.DispGetIDsOfNames
92
+ _DispGetIDsOfNames.argtypes = [
93
+ POINTER(ITypeInfo),
94
+ POINTER(c_wchar_p),
95
+ UINT,
96
+ POINTER(DISPID),
97
+ ]
98
+ _DispGetIDsOfNames.restype = (
99
+ LONG # technically, it is a HRESULT, but we want to avoid the OSError
100
+ )
101
+
102
+ _DispInvoke = _oleaut32.DispInvoke
103
+ _DispInvoke.argtypes = [
104
+ LPVOID,
105
+ POINTER(ITypeInfo),
106
+ DISPID,
107
+ WORD,
108
+ POINTER(DISPPARAMS),
109
+ POINTER(VARIANT),
110
+ POINTER(EXCEPINFO),
111
+ POINTER(UINT),
112
+ ]
113
+ _DispInvoke.restype = (
114
+ LONG # technically, it is a HRESULT, but we want to avoid the OSError
115
+ )
116
+
117
+
118
+ _ole32_nohresult = WinDLL("ole32")
119
+ _ole32 = OleDLL("ole32")
120
+
121
+ _CoInitialize = _ole32_nohresult.CoInitialize
122
+ _CoInitialize.argtypes = [LPVOID]
123
+ _CoInitialize.restype = (
124
+ LONG # technically, it is a HRESULT, but we want to avoid the OSError
125
+ )
126
+
127
+ _CoAddRefServerProcess = _ole32.CoAddRefServerProcess
128
+ _CoAddRefServerProcess.argtypes = []
129
+ _CoAddRefServerProcess.restype = ULONG
130
+
131
+ _CoReleaseServerProcess = _ole32.CoReleaseServerProcess
132
+ _CoReleaseServerProcess.argtypes = []
133
+ _CoReleaseServerProcess.restype = ULONG
134
+
135
+
136
+ _user32 = WinDLL("user32")
137
+
138
+ _PostQuitMessage = _user32.PostQuitMessage
139
+ _PostQuitMessage.argtypes = [INT]
140
+ _PostQuitMessage.restype = None
141
+
85
142
 
86
143
  class LocalServer(object):
87
144
  _queue: Optional[queue.Queue] = None
88
145
 
89
146
  def run(self, classobjects: Sequence["hints.localserver.ClassFactory"]) -> None:
90
- # Use windll instead of oledll so that we don't get an
91
- # exception on a FAILED hresult:
92
- hr = windll.ole32.CoInitialize(None)
147
+ hr = _CoInitialize(None)
93
148
  if hresult.RPC_E_CHANGED_MODE == hr:
94
149
  # we're running in MTA: no message pump needed
95
150
  _debug("Server running in MTA")
@@ -100,7 +155,7 @@ class LocalServer(object):
100
155
  if hr >= 0:
101
156
  # we need a matching CoUninitialize() call for a successful
102
157
  # CoInitialize().
103
- windll.ole32.CoUninitialize()
158
+ _CoUninitialize()
104
159
  self.run_sta()
105
160
 
106
161
  for obj in classobjects:
@@ -116,15 +171,15 @@ class LocalServer(object):
116
171
  self._queue.get()
117
172
 
118
173
  def Lock(self) -> None:
119
- oledll.ole32.CoAddRefServerProcess()
174
+ _CoAddRefServerProcess()
120
175
 
121
176
  def Unlock(self) -> None:
122
- rc = oledll.ole32.CoReleaseServerProcess()
177
+ rc = _CoReleaseServerProcess()
123
178
  if rc == 0:
124
179
  if self._queue:
125
180
  self._queue.put(42)
126
181
  else:
127
- windll.user32.PostQuitMessage(0)
182
+ _PostQuitMessage(0)
128
183
 
129
184
 
130
185
  class InprocServer(object):
@@ -401,7 +456,7 @@ class COMObject(object):
401
456
  tinfo = self.__typeinfo
402
457
  except AttributeError:
403
458
  return hresult.E_NOTIMPL
404
- return windll.oleaut32.DispGetIDsOfNames(tinfo, rgszNames, cNames, rgDispId)
459
+ return _DispGetIDsOfNames(tinfo, rgszNames, cNames, rgDispId)
405
460
 
406
461
  def IDispatch_Invoke(
407
462
  self,
@@ -432,7 +487,7 @@ class COMObject(object):
432
487
  # an error.
433
488
  interface = self._com_interfaces_[0]
434
489
  ptr = self._com_pointers_[interface._iid_]
435
- return windll.oleaut32.DispInvoke(
490
+ return _DispInvoke(
436
491
  ptr,
437
492
  tinfo,
438
493
  dispIdMember,
@@ -1,12 +1,20 @@
1
1
  import ctypes
2
- from typing import Any, Literal, NamedTuple
3
- from typing import Dict, List, Tuple, Type
4
- from typing import Optional, Union as _UnionT
5
- from typing import Callable, Iterator
2
+ from typing import (
3
+ Any,
4
+ Callable,
5
+ Dict,
6
+ Iterator,
7
+ List,
8
+ Literal,
9
+ NamedTuple,
10
+ Optional,
11
+ Tuple,
12
+ Type,
13
+ )
14
+ from typing import Union as _UnionT
6
15
 
7
- from comtypes import _CData
8
16
  import comtypes
9
-
17
+ from comtypes import _CData
10
18
 
11
19
  _PositionalParamFlagType = Tuple[int, Optional[str]]
12
20
  _OptionalParamFlagType = Tuple[int, Optional[str], Any]
@@ -1,5 +1,6 @@
1
1
  # comtypes._meta helper module
2
2
  from ctypes import POINTER, c_void_p, cast
3
+
3
4
  import comtypes
4
5
 
5
6
  ################################################################
@@ -4,7 +4,6 @@ from typing import Type
4
4
 
5
5
  from comtypes import patcher
6
6
 
7
-
8
7
  _all_slice = slice(None, None, None)
9
8
 
10
9
 
@@ -1,10 +1,15 @@
1
- from ctypes import _SimpleCData, windll
2
- from typing import Any, Callable, TYPE_CHECKING
1
+ from ctypes import WinDLL, _SimpleCData
2
+ from typing import TYPE_CHECKING, Any, Callable
3
3
 
4
4
  if TYPE_CHECKING:
5
5
  from comtypes import hints # type: ignore
6
6
 
7
7
 
8
+ _oleaut32 = WinDLL("oleaut32")
9
+
10
+ _SysFreeString = _oleaut32.SysFreeString
11
+
12
+
8
13
  class BSTR(_SimpleCData):
9
14
  """The windows BSTR data type"""
10
15
 
@@ -18,9 +23,7 @@ class BSTR(_SimpleCData):
18
23
  self._needsfree = True
19
24
  return self.value
20
25
 
21
- def __del__(
22
- self, _free: Callable[["BSTR"], Any] = windll.oleaut32.SysFreeString
23
- ) -> None:
26
+ def __del__(self, _free: Callable[["BSTR"], Any] = _SysFreeString) -> None:
24
27
  # Free the string if self owns the memory
25
28
  # or if instructed by __ctypes_from_outparam__.
26
29
  if self._b_base_ is None or self._needsfree:
@@ -35,3 +38,7 @@ class BSTR(_SimpleCData):
35
38
  # right thing, it doesn't ensure that SysFreeString is called
36
39
  # on destruction.
37
40
  return cls(value)
41
+
42
+
43
+ _SysFreeString.argtypes = [BSTR]
44
+ _SysFreeString.restype = None
@@ -1,5 +1,4 @@
1
- from ctypes import pythonapi, py_object
2
-
1
+ from ctypes import py_object, pythonapi
3
2
 
4
3
  pythonapi.PyInstanceMethod_New.argtypes = [py_object]
5
4
  pythonapi.PyInstanceMethod_New.restype = py_object
@@ -1,26 +1,28 @@
1
- from ctypes import c_ulong, c_ushort, c_void_p, c_wchar_p, HRESULT, Structure
2
- from ctypes import byref, cast, _Pointer, POINTER, pointer
3
-
4
- # fmt: off
5
- from typing import ( # noqa
6
- Any, overload, TYPE_CHECKING, TypeVar,
7
- # instead of `builtins`. see PEP585
8
- Type,
9
- # instead of `collections.abc`. see PEP585
10
- Callable,
11
- # instead of `A | B` and `None | A`. see PEP604
12
- Optional,
1
+ from ctypes import (
2
+ HRESULT,
3
+ POINTER,
4
+ OleDLL,
5
+ Structure,
6
+ byref,
7
+ c_ulong,
8
+ c_ushort,
9
+ c_void_p,
10
+ c_wchar_p,
11
+ cast,
12
+ pointer,
13
13
  )
14
- # fmt: on
15
- if TYPE_CHECKING:
16
- from comtypes import hints as hints # noqa # type: ignore
14
+ from ctypes.wintypes import DWORD, LPCWSTR, LPVOID
15
+ from typing import TYPE_CHECKING, Any, Callable, Optional, Type, TypeVar, overload
17
16
 
18
- from comtypes import GUID
19
- from comtypes import CLSCTX_SERVER, CLSCTX_LOCAL_SERVER, CLSCTX_REMOTE_SERVER
20
- from comtypes import _ole32, oledll, DWORD
17
+ from comtypes import CLSCTX_LOCAL_SERVER, CLSCTX_REMOTE_SERVER, CLSCTX_SERVER, GUID
21
18
  from comtypes._memberspec import COMMETHOD
22
19
  from comtypes._post_coinit.unknwn import IUnknown
23
20
 
21
+ if TYPE_CHECKING:
22
+ from ctypes import _Pointer
23
+
24
+ from comtypes import hints as hints # noqa # type: ignore
25
+
24
26
 
25
27
  def _is_object(obj):
26
28
  """This function determines if the argument is a COM object. It
@@ -98,7 +100,7 @@ def CoGetObject(displayname: str, interface: Optional[Type[IUnknown]]) -> IUnkno
98
100
  interface = IUnknown
99
101
  punk = POINTER(interface)()
100
102
  # Do we need a way to specify the BIND_OPTS parameter?
101
- _ole32.CoGetObject(str(displayname), None, byref(interface._iid_), byref(punk))
103
+ _CoGetObject(str(displayname), None, byref(interface._iid_), byref(punk))
102
104
  return punk # type: ignore
103
105
 
104
106
 
@@ -134,7 +136,7 @@ def CoCreateInstance(
134
136
  interface = IUnknown
135
137
  p = POINTER(interface)()
136
138
  iid = interface._iid_
137
- _ole32.CoCreateInstance(byref(clsid), punkouter, clsctx, byref(iid), byref(p))
139
+ _CoCreateInstance(byref(clsid), punkouter, clsctx, byref(iid), byref(p))
138
140
  return p # type: ignore
139
141
 
140
142
 
@@ -178,7 +180,7 @@ def GetActiveObject(
178
180
  ) -> IUnknown:
179
181
  """Retrieves a pointer to a running object"""
180
182
  p = POINTER(IUnknown)()
181
- oledll.oleaut32.GetActiveObject(byref(clsid), None, byref(p))
183
+ _GetActiveObject(byref(clsid), None, byref(p))
182
184
  if interface is not None:
183
185
  p = p.QueryInterface(interface) # type: ignore
184
186
  return p # type: ignore
@@ -236,6 +238,16 @@ class _COSERVERINFO(Structure):
236
238
  dwReserved2: int
237
239
 
238
240
 
241
+ _oleaut32 = OleDLL("oleaut32")
242
+
243
+ REFCLSID = POINTER(GUID)
244
+ _GetActiveObject = _oleaut32.GetActiveObject
245
+ _GetActiveObject.argtypes = [REFCLSID, LPVOID, POINTER(POINTER(IUnknown))]
246
+ _GetActiveObject.restype = HRESULT
247
+
248
+
249
+ _ole32 = OleDLL("ole32")
250
+
239
251
  COSERVERINFO = _COSERVERINFO
240
252
  _CoGetClassObject = _ole32.CoGetClassObject
241
253
  _CoGetClassObject.argtypes = [
@@ -245,6 +257,28 @@ _CoGetClassObject.argtypes = [
245
257
  POINTER(GUID),
246
258
  POINTER(c_void_p),
247
259
  ]
260
+ _CoGetClassObject.restype = HRESULT
261
+
262
+ _CoCreateInstance = _ole32.CoCreateInstance
263
+ _CoCreateInstance.argtypes = [
264
+ REFCLSID,
265
+ POINTER(IUnknown),
266
+ DWORD,
267
+ POINTER(GUID),
268
+ POINTER(LPVOID),
269
+ ]
270
+ _CoCreateInstance.restype = HRESULT
271
+
272
+ _CoCreateInstanceEx = _ole32.CoCreateInstanceEx
273
+ _CoCreateInstanceEx.argtypes = [
274
+ REFCLSID,
275
+ POINTER(IUnknown),
276
+ DWORD,
277
+ POINTER(COSERVERINFO),
278
+ DWORD,
279
+ POINTER(MULTI_QI),
280
+ ]
281
+ _CoCreateInstanceEx.restype = HRESULT
248
282
 
249
283
 
250
284
  class tagBIND_OPTS(Structure):
@@ -258,6 +292,9 @@ class tagBIND_OPTS(Structure):
258
292
 
259
293
  # XXX Add __init__ which sets cbStruct?
260
294
  BIND_OPTS = tagBIND_OPTS
295
+ _CoGetObject = _ole32.CoGetObject
296
+ _CoGetObject.argtypes = [LPCWSTR, POINTER(BIND_OPTS), POINTER(GUID), POINTER(LPVOID)]
297
+ _CoGetObject.restype = HRESULT
261
298
 
262
299
 
263
300
  class tagBIND_OPTS2(Structure):
@@ -360,7 +397,5 @@ def CoCreateInstanceEx(
360
397
  interface = IUnknown
361
398
  multiqi = MULTI_QI()
362
399
  multiqi.pIID = pointer(interface._iid_) # type: ignore
363
- _ole32.CoCreateInstanceEx(
364
- byref(clsid), None, clsctx, pServerInfo, 1, byref(multiqi)
365
- )
400
+ _CoCreateInstanceEx(byref(clsid), None, clsctx, pServerInfo, 1, byref(multiqi))
366
401
  return cast(multiqi.pItf, POINTER(interface)) # type: ignore
@@ -1,11 +1,10 @@
1
1
  # https://learn.microsoft.com/en-us/windows/win32/api/unknwn/
2
2
 
3
3
  import logging
4
- import sys
5
4
  from ctypes import HRESULT, POINTER, byref, c_ulong, c_void_p
6
5
  from typing import TYPE_CHECKING, ClassVar, List, Optional, Type, TypeVar
7
6
 
8
- from comtypes import GUID, _ole32_nohresult, com_interface_registry
7
+ from comtypes import GUID, _CoUninitialize, com_interface_registry
9
8
  from comtypes._memberspec import STDMETHOD, ComMemberGenerator, DispMemberGenerator
10
9
  from comtypes._post_coinit import _cominterface_meta_patcher as _meta_patch
11
10
  from comtypes._post_coinit.instancemethod import instancemethod
@@ -17,12 +16,9 @@ logger = logging.getLogger(__name__)
17
16
 
18
17
 
19
18
  def _shutdown(
20
- func=_ole32_nohresult.CoUninitialize,
19
+ func=_CoUninitialize,
21
20
  _debug=logger.debug,
22
- _exc_clear=getattr(sys, "exc_clear", lambda: None),
23
21
  ):
24
- # Make sure no COM pointers stay in exception frames.
25
- _exc_clear()
26
22
  # Sometimes, CoUninitialize, running at Python shutdown,
27
23
  # raises an exception. We suppress this when __debug__ is
28
24
  # False.
@@ -1,9 +1,9 @@
1
1
  """SAFEARRAY api functions, data types, and constants."""
2
2
 
3
- from ctypes import c_uint, c_ushort, c_void_p, POINTER, Structure, WinDLL
3
+ from ctypes import POINTER, Structure, WinDLL, c_uint, c_ushort, c_void_p
4
4
  from ctypes.wintypes import DWORD, LONG, UINT, USHORT
5
5
 
6
- from comtypes import HRESULT, GUID
6
+ from comtypes import GUID, HRESULT
7
7
 
8
8
  ################################################################
9
9
  # if __debug__:
@@ -575,23 +575,29 @@ class tagVARIANT(Structure):
575
575
  VARIANT = tagVARIANT
576
576
  VARIANTARG = VARIANT
577
577
 
578
+ _oleaut32_nohresult = WinDLL("oleaut32")
579
+
580
+ _SysAllocStringLen = _oleaut32_nohresult.SysAllocStringLen
581
+ _SysAllocStringLen.argtypes = c_wchar_p, c_uint
582
+ _SysAllocStringLen.restype = c_void_p
583
+
578
584
  _oleaut32 = OleDLL("oleaut32")
579
585
 
580
586
  _VariantChangeType = _oleaut32.VariantChangeType
581
587
  _VariantChangeType.argtypes = (POINTER(VARIANT), POINTER(VARIANT), c_ushort, VARTYPE)
588
+ _VariantChangeType.restype = HRESULT
582
589
 
583
590
  _VariantClear = _oleaut32.VariantClear
584
591
  _VariantClear.argtypes = (POINTER(VARIANT),)
585
-
586
- _SysAllocStringLen = windll.oleaut32.SysAllocStringLen
587
- _SysAllocStringLen.argtypes = c_wchar_p, c_uint
588
- _SysAllocStringLen.restype = c_void_p
592
+ _VariantClear.restype = HRESULT
589
593
 
590
594
  _VariantCopy = _oleaut32.VariantCopy
591
595
  _VariantCopy.argtypes = POINTER(VARIANT), POINTER(VARIANT)
596
+ _VariantCopy.restype = HRESULT
592
597
 
593
598
  _VariantCopyInd = _oleaut32.VariantCopyInd
594
599
  _VariantCopyInd.argtypes = POINTER(VARIANT), POINTER(VARIANT)
600
+ _VariantCopyInd.restype = HRESULT
595
601
 
596
602
  # some commonly used VARIANT instances
597
603
  VARIANT.null = VARIANT(None)