win32more-core 0.7.0__tar.gz

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.
@@ -0,0 +1,160 @@
1
+ # Byte-compiled / optimized / DLL files
2
+ __pycache__/
3
+ *.py[cod]
4
+ *$py.class
5
+
6
+ # C extensions
7
+ *.so
8
+
9
+ # Distribution / packaging
10
+ .Python
11
+ build/
12
+ develop-eggs/
13
+ dist/
14
+ downloads/
15
+ eggs/
16
+ .eggs/
17
+ lib/
18
+ lib64/
19
+ parts/
20
+ sdist/
21
+ var/
22
+ wheels/
23
+ share/python-wheels/
24
+ *.egg-info/
25
+ .installed.cfg
26
+ *.egg
27
+ MANIFEST
28
+
29
+ # PyInstaller
30
+ # Usually these files are written by a python script from a template
31
+ # before PyInstaller builds the exe, so as to inject date/other infos into it.
32
+ *.manifest
33
+ *.spec
34
+
35
+ # Installer logs
36
+ pip-log.txt
37
+ pip-delete-this-directory.txt
38
+
39
+ # Unit test / coverage reports
40
+ htmlcov/
41
+ .tox/
42
+ .nox/
43
+ .coverage
44
+ .coverage.*
45
+ .cache
46
+ nosetests.xml
47
+ coverage.xml
48
+ *.cover
49
+ *.py,cover
50
+ .hypothesis/
51
+ .pytest_cache/
52
+ cover/
53
+
54
+ # Translations
55
+ *.mo
56
+ *.pot
57
+
58
+ # Django stuff:
59
+ *.log
60
+ local_settings.py
61
+ db.sqlite3
62
+ db.sqlite3-journal
63
+
64
+ # Flask stuff:
65
+ instance/
66
+ .webassets-cache
67
+
68
+ # Scrapy stuff:
69
+ .scrapy
70
+
71
+ # Sphinx documentation
72
+ docs/_build/
73
+
74
+ # PyBuilder
75
+ .pybuilder/
76
+ target/
77
+
78
+ # Jupyter Notebook
79
+ .ipynb_checkpoints
80
+
81
+ # IPython
82
+ profile_default/
83
+ ipython_config.py
84
+
85
+ # pyenv
86
+ # For a library or package, you might want to ignore these files since the code is
87
+ # intended to run in multiple environments; otherwise, check them in:
88
+ # .python-version
89
+
90
+ # pipenv
91
+ # According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
92
+ # However, in case of collaboration, if having platform-specific dependencies or dependencies
93
+ # having no cross-platform support, pipenv may install dependencies that don't work, or not
94
+ # install all needed dependencies.
95
+ #Pipfile.lock
96
+
97
+ # poetry
98
+ # Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
99
+ # This is especially recommended for binary packages to ensure reproducibility, and is more
100
+ # commonly ignored for libraries.
101
+ # https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
102
+ #poetry.lock
103
+
104
+ # pdm
105
+ # Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
106
+ #pdm.lock
107
+ # pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it
108
+ # in version control.
109
+ # https://pdm.fming.dev/#use-with-ide
110
+ .pdm.toml
111
+
112
+ # PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
113
+ __pypackages__/
114
+
115
+ # Celery stuff
116
+ celerybeat-schedule
117
+ celerybeat.pid
118
+
119
+ # SageMath parsed files
120
+ *.sage.py
121
+
122
+ # Environments
123
+ .env
124
+ .venv
125
+ env/
126
+ venv/
127
+ ENV/
128
+ env.bak/
129
+ venv.bak/
130
+
131
+ # Spyder project settings
132
+ .spyderproject
133
+ .spyproject
134
+
135
+ # Rope project settings
136
+ .ropeproject
137
+
138
+ # mkdocs documentation
139
+ /site
140
+
141
+ # mypy
142
+ .mypy_cache/
143
+ .dmypy.json
144
+ dmypy.json
145
+
146
+ # Pyre type checker
147
+ .pyre/
148
+
149
+ # pytype static type analyzer
150
+ .pytype/
151
+
152
+ # Cython debug symbols
153
+ cython_debug/
154
+
155
+ # PyCharm
156
+ # JetBrains specific template is maintained in a separate JetBrains.gitignore that can
157
+ # be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
158
+ # and can be added to the global gitignore or merged into this file. For a more nuclear
159
+ # option (not recommended) you can uncomment the following to ignore the entire idea folder.
160
+ #.idea/
@@ -0,0 +1,3 @@
1
+ Metadata-Version: 2.4
2
+ Name: win32more-core
3
+ Version: 0.7.0
@@ -0,0 +1,11 @@
1
+ [project]
2
+ name = "win32more-core"
3
+ version = "0.7.0"
4
+ dependencies = []
5
+
6
+ [build-system]
7
+ requires = ["hatchling >= 1.26"]
8
+ build-backend = "hatchling.build"
9
+
10
+ [tool.hatch.build.targets.wheel]
11
+ packages = ["src/win32more"]
@@ -0,0 +1,36 @@
1
+ # ruff: noqa: F401
2
+ from . import _win32api
3
+ from ._boxing import box_value, unbox_value
4
+ from ._comclass import ComClass
5
+ from ._comerror import ComError
6
+ from ._win32 import (
7
+ FAILED,
8
+ SUCCEEDED,
9
+ WINFUNCTYPE,
10
+ Boolean,
11
+ Byte,
12
+ Bytes,
13
+ Char,
14
+ Double,
15
+ Guid,
16
+ Int16,
17
+ Int32,
18
+ Int64,
19
+ IntPtr,
20
+ SByte,
21
+ Single,
22
+ String,
23
+ UInt16,
24
+ UInt32,
25
+ UInt64,
26
+ UIntPtr,
27
+ Void,
28
+ VoidPtr,
29
+ WinError,
30
+ windll,
31
+ )
32
+
33
+ # Initialize COM Multithreaded Apartment.
34
+ # Call CoInitializeEx(None, COINIT_APARTMENTTHREADED) explicitly for Single-Threaded Apartment.
35
+ if FAILED(_win32api.CoIncrementMTAUsage(VoidPtr())):
36
+ raise WinError()
@@ -0,0 +1,141 @@
1
+ from __future__ import annotations
2
+
3
+ from ._win32api import IInspectable
4
+
5
+
6
+ # FIXME: Add more conversion.
7
+ def box_value(value: object) -> IInspectable:
8
+ from win32more.Windows.Foundation import PropertyValue
9
+
10
+ if isinstance(value, str):
11
+ return PropertyValue.CreateString(value)
12
+ elif isinstance(value, bool):
13
+ return PropertyValue.CreateBoolean(value)
14
+ raise NotImplementedError(f"box_value: {type(value)}")
15
+
16
+
17
+ def unbox_value(value: IInspectable):
18
+ from win32more.Windows.Foundation import IPropertyValue, PropertyType
19
+
20
+ property_value = value.as_(IPropertyValue)
21
+
22
+ if property_value.Type == PropertyType.Empty:
23
+ return None
24
+ elif property_value.Type == PropertyType.UInt8:
25
+ return property_value.GetUInt8()
26
+ elif property_value.Type == PropertyType.Int16:
27
+ return property_value.GetInt16()
28
+ elif property_value.Type == PropertyType.UInt16:
29
+ return property_value.GetUInt16()
30
+ elif property_value.Type == PropertyType.Int32:
31
+ return property_value.GetInt32()
32
+ elif property_value.Type == PropertyType.UInt32:
33
+ return property_value.GetUInt32()
34
+ elif property_value.Type == PropertyType.Int64:
35
+ return property_value.GetInt64()
36
+ elif property_value.Type == PropertyType.UInt64:
37
+ return property_value.GetUInt64()
38
+ elif property_value.Type == PropertyType.Single:
39
+ return property_value.GetSingle()
40
+ elif property_value.Type == PropertyType.Double:
41
+ return property_value.GetDouble()
42
+ elif property_value.Type == PropertyType.Char16:
43
+ return property_value.GetChar16()
44
+ elif property_value.Type == PropertyType.Boolean:
45
+ return property_value.GetBoolean()
46
+ elif property_value.Type == PropertyType.String:
47
+ return property_value.GetString()
48
+ elif property_value.Type == PropertyType.Inspectable:
49
+ return value
50
+ elif property_value.Type == PropertyType.DateTime:
51
+ return property_value.GetDateTime()
52
+ elif property_value.Type == PropertyType.TimeSpan:
53
+ return property_value.GetTimeSpan()
54
+ elif property_value.Type == PropertyType.Guid:
55
+ return property_value.GetGuid()
56
+ elif property_value.Type == PropertyType.Point:
57
+ return property_value.GetPoint()
58
+ elif property_value.Type == PropertyType.Size:
59
+ return property_value.GetSize()
60
+ elif property_value.Type == PropertyType.Rect:
61
+ return property_value.GetRect()
62
+ elif property_value.Type == PropertyType.UInt8Array:
63
+ r = []
64
+ property_value.GetUInt8Array(r)
65
+ return r
66
+ elif property_value.Type == PropertyType.Int16Array:
67
+ r = []
68
+ property_value.GetInt16Array(r)
69
+ return r
70
+ elif property_value.Type == PropertyType.UInt16Array:
71
+ r = []
72
+ property_value.GetUInt16Array(r)
73
+ return r
74
+ elif property_value.Type == PropertyType.Int32Array:
75
+ r = []
76
+ property_value.GetInt32Array(r)
77
+ return r
78
+ elif property_value.Type == PropertyType.UInt32Array:
79
+ r = []
80
+ property_value.GetUInt32Array(r)
81
+ return r
82
+ elif property_value.Type == PropertyType.Int64Array:
83
+ r = []
84
+ property_value.GetInt64Array(r)
85
+ return r
86
+ elif property_value.Type == PropertyType.UInt64Array:
87
+ r = []
88
+ property_value.GetUInt64Array(r)
89
+ return r
90
+ elif property_value.Type == PropertyType.SingleArray:
91
+ r = []
92
+ property_value.GetSingleArray(r)
93
+ return r
94
+ elif property_value.Type == PropertyType.DoubleArray:
95
+ r = []
96
+ property_value.GetDoubleArray(r)
97
+ return r
98
+ elif property_value.Type == PropertyType.Char16Array:
99
+ r = []
100
+ property_value.GetChar16Array(r)
101
+ return r
102
+ elif property_value.Type == PropertyType.BooleanArray:
103
+ r = []
104
+ property_value.GetBooleanArray(r)
105
+ return r
106
+ elif property_value.Type == PropertyType.StringArray:
107
+ r = []
108
+ property_value.GetStringArray(r)
109
+ return r
110
+ elif property_value.Type == PropertyType.InspectableArray:
111
+ r = []
112
+ property_value.GetInspectableArray(r)
113
+ return r
114
+ elif property_value.Type == PropertyType.DateTimeArray:
115
+ r = []
116
+ property_value.GetDateTimeArray(r)
117
+ return r
118
+ elif property_value.Type == PropertyType.TimeSpanArray:
119
+ r = []
120
+ property_value.GetTimeSpanArray(r)
121
+ return r
122
+ elif property_value.Type == PropertyType.GuidArray:
123
+ r = []
124
+ property_value.GetGuidArray(r)
125
+ return r
126
+ elif property_value.Type == PropertyType.PointArray:
127
+ r = []
128
+ property_value.GetPointArray(r)
129
+ return r
130
+ elif property_value.Type == PropertyType.SizeArray:
131
+ r = []
132
+ property_value.GetSizeArray(r)
133
+ return r
134
+ elif property_value.Type == PropertyType.RectArray:
135
+ r = []
136
+ property_value.GetRectArray(r)
137
+ return r
138
+ # elif property_value.Type == PropertyType.OtherType:
139
+ # elif property_value.Type == PropertyType.OtherTypeArray:
140
+ else:
141
+ raise NotImplementedError(f"unbox_value: {property_value.Type}")
@@ -0,0 +1,36 @@
1
+ from __future__ import annotations
2
+
3
+ from ctypes import wstring_at
4
+
5
+ from ._win32 import UIntPtr
6
+ from ._win32api import BSTR, SysAllocStringLen, SysFreeString, SysStringLen
7
+
8
+
9
+ class bstr(BSTR):
10
+ def __init__(self, obj=None, own=False):
11
+ super().__init__()
12
+ if obj is None:
13
+ self.value = 0
14
+ elif isinstance(obj, str):
15
+ self.value = SysAllocStringLen(obj, len(obj), _as_intptr=True)
16
+ else:
17
+ raise ValueError(obj)
18
+ self._own = own
19
+
20
+ def __del__(self):
21
+ if getattr(self, "_own", False):
22
+ self.clear()
23
+
24
+ def clear(self):
25
+ if self.value:
26
+ SysFreeString(self)
27
+ self.value = 0
28
+
29
+ def __len__(self):
30
+ return SysStringLen(self)
31
+
32
+ def __str__(self):
33
+ return wstring_at(self, len(self))
34
+
35
+ def __int__(self):
36
+ return UIntPtr.from_buffer(self).value
@@ -0,0 +1,298 @@
1
+ from __future__ import annotations
2
+
3
+ import logging
4
+ import sys
5
+ from collections.abc import Iterable
6
+ from contextlib import ExitStack
7
+ from ctypes import POINTER, Structure, addressof, c_void_p, cast, py_object, sizeof
8
+ from functools import partial
9
+ from typing import Any, _GenericAlias, get_args, get_origin
10
+
11
+ from ._comerror import set_error_info
12
+ from ._generic import (
13
+ generic_get_type_hints,
14
+ get_origin_or_itself,
15
+ get_original_class,
16
+ get_specialized_bases,
17
+ is_generic_alias,
18
+ )
19
+ from ._hstr import hstr
20
+ from ._ro import ro_get_parameterized_type_instance_iid
21
+ from ._win32 import WINFUNCTYPE, ComMethod, ComPtr, Guid, UInt32, Void, VoidPtr, commethod
22
+ from ._win32api import (
23
+ E_FAIL,
24
+ E_NOINTERFACE,
25
+ HRESULT,
26
+ HSTRING,
27
+ S_OK,
28
+ BaseTrust,
29
+ CoTaskMemAlloc,
30
+ IAgileObject,
31
+ IInspectable,
32
+ IUnknown,
33
+ RoOriginateError,
34
+ TrustLevel,
35
+ )
36
+
37
+ logger = logging.getLogger(__name__)
38
+
39
+
40
+ class _lazy_winrt:
41
+ def __getattr__(self, name):
42
+ global _winrt
43
+ from . import _winrt
44
+
45
+ return getattr(_winrt, name)
46
+
47
+
48
+ _winrt = _lazy_winrt()
49
+
50
+
51
+ def is_com_class(cls):
52
+ return issubclass(get_origin_or_itself(cls), ComPtr)
53
+
54
+
55
+ def is_com_instance(obj):
56
+ return isinstance(obj, ComPtr)
57
+
58
+
59
+ class ComClass(ComPtr):
60
+ _keep_reference_in_python_world_ = {}
61
+
62
+ def __init__(self, *args, **kwargs):
63
+ super().__init__(*args, **kwargs)
64
+ self._iid_vtbls = self._make_iid_vtbls()
65
+ self.value = addressof(self._iid_vtbls[0][1]) # select default interface
66
+ self._refcount = 0
67
+ self.AddRef()
68
+ self._inner = self._compose()
69
+
70
+ def _make_iid_vtbls(self) -> list[tuple[Guid, Vtbl]]:
71
+ iid_vtbls = []
72
+ for interface in self._implemented_interfaces():
73
+ iid = self._get_iid(interface)
74
+ vtbl = Vtbl(self, interface)
75
+ iid_vtbls.append((iid, vtbl))
76
+ return iid_vtbls
77
+
78
+ def _get_iid(self, interface):
79
+ if is_generic_alias(interface):
80
+ return ro_get_parameterized_type_instance_iid(interface)
81
+ elif "_iid_" in interface.__dict__:
82
+ return interface.__dict__["_iid_"]
83
+ else:
84
+ raise ValueError("Cannot get iid")
85
+
86
+ def _implemented_interfaces(self) -> list[_GenericAlias | type]:
87
+ r = []
88
+ for base in self._enumerate_specialized_bases_recursively(get_original_class(self)):
89
+ if is_generic_alias(base) and "_piid_" in get_origin(base).__dict__:
90
+ r.append(base)
91
+ elif "_iid_" in base.__dict__:
92
+ r.append(base)
93
+ r.append(IAgileObject)
94
+ r.append(ISelf)
95
+ return r
96
+
97
+ def _enumerate_specialized_bases_recursively(self, cls: _GenericAlias | type) -> Iterable[_GenericAlias | type]:
98
+ for base in get_specialized_bases(cls):
99
+ yield base
100
+ yield from self._enumerate_specialized_bases_recursively(base)
101
+
102
+ @classmethod
103
+ def _runtime_class_name(cls) -> str:
104
+ return f"{cls.__module__}.{cls.__qualname__}"
105
+
106
+ def _compose(self) -> IInspectable:
107
+ for base in type(self).__mro__:
108
+ # FIXME: ComposableAttribute should be checked.
109
+ if issubclass(base, IInspectable) and "CreateInstance" in base.__dict__:
110
+ inner = IInspectable()
111
+ base.CreateInstance(self, inner)
112
+ return inner
113
+ return None
114
+
115
+ def QueryInterface(self, riid: POINTER(Guid), ppvObject: POINTER(VoidPtr)) -> HRESULT:
116
+ for iid, vtbl in self._iid_vtbls:
117
+ if riid[0] == iid:
118
+ ppvObject[0] = addressof(vtbl)
119
+ self.AddRef()
120
+ return S_OK
121
+ if self._inner is not None:
122
+ return self._inner.QueryInterface(riid, ppvObject)
123
+ return E_NOINTERFACE
124
+
125
+ def AddRef(self) -> UInt32:
126
+ self._refcount += 1
127
+ if self._refcount == 1:
128
+ self._keep_reference_in_python_world_[id(self)] = self
129
+ return self._refcount
130
+
131
+ def Release(self) -> UInt32:
132
+ self._refcount -= 1
133
+ if self._refcount == 0:
134
+ del self._keep_reference_in_python_world_[id(self)]
135
+ return self._refcount
136
+
137
+ def GetIids(self, iidCount: POINTER(UInt32), iids: POINTER(POINTER(Guid))) -> HRESULT:
138
+ iidCount[0] = len(self._iid_vtbls)
139
+ iids[0] = CoTaskMemAlloc(sizeof(VoidPtr) * len(self._iid_vtbls))
140
+ if iids[0] is None:
141
+ return E_FAIL
142
+ for i, (iid, vtbl) in enumerate(self._iid_vtbls):
143
+ iids[0][i] = iid
144
+ return S_OK
145
+
146
+ def GetRuntimeClassName(self, className: POINTER(HSTRING)) -> HRESULT:
147
+ className[0] = hstr(self._runtime_class_name())
148
+ return S_OK
149
+
150
+ def GetTrustLevel(self, trustLevel: POINTER(TrustLevel)) -> HRESULT:
151
+ trustLevel[0] = BaseTrust
152
+ return S_OK
153
+
154
+ # ISelf.GetSelf()
155
+ def GetSelf(self) -> object:
156
+ return self
157
+
158
+
159
+ class Vtbl(Structure):
160
+ _fields_ = [("lpvtbl", POINTER(c_void_p))]
161
+
162
+ def __init__(self, owner, interface):
163
+ self._owner = owner
164
+ self._interface = interface
165
+ self._keep_reference_in_python_world_ = []
166
+ self.lpvtbl = self._make_lpvtbl()
167
+
168
+ def _make_lpvtbl(self):
169
+ methods = self._interface_methods()
170
+ vtbl_size = max(method._vtbl_index for method in methods) + 1
171
+ lpvtbl = (c_void_p * vtbl_size)()
172
+ for method in methods:
173
+ if isinstance(method, _winrt.WinrtMethod):
174
+ lpvtbl[method._vtbl_index] = self._make_thunk_winrt(method)
175
+ else:
176
+ lpvtbl[method._vtbl_index] = self._make_thunk_com(method)
177
+ return lpvtbl
178
+
179
+ def _interface_methods(self):
180
+ if sys.version_info < (3, 10) and is_generic_alias(self._interface):
181
+ interface = get_origin(self._interface)
182
+ else:
183
+ interface = self._interface
184
+ methods = []
185
+ for name in dir(interface):
186
+ if isinstance(getattr(interface, name), (ComMethod, _winrt.WinrtMethod)):
187
+ methods.append(getattr(interface, name))
188
+ return methods
189
+
190
+ def _make_thunk_com(self, method):
191
+ hints = generic_get_type_hints(method._prototype, self._interface)
192
+ restype = hints.pop("return")
193
+ argtypes = [self._make_allocator(t) for t in hints.values()]
194
+ closure = partial(self._com_callback_error_check, getattr(self._owner, method._prototype.__name__))
195
+ thunk = WINFUNCTYPE(restype, c_void_p, *argtypes)(closure)
196
+ self._keep_reference_in_python_world_.append(thunk)
197
+ return cast(thunk, c_void_p)
198
+
199
+ def _make_thunk_winrt(self, method):
200
+ hints = generic_get_type_hints(method._prototype, self._interface)
201
+ restype = hints.pop("return")
202
+ argtypes = []
203
+ for type_ in hints.values():
204
+ if _winrt.is_passarray_class(type_):
205
+ argtypes.append(UInt32)
206
+ argtypes.append(POINTER(get_args(type_)[0]))
207
+ elif _winrt.is_fillarray_class(type_):
208
+ argtypes.append(UInt32)
209
+ argtypes.append(POINTER(get_args(type_)[0]))
210
+ elif _winrt.is_receivearray_class(type_):
211
+ argtypes.append(POINTER(UInt32))
212
+ argtypes.append(POINTER(POINTER(get_args(type_)[0])))
213
+ else:
214
+ argtypes.append(self._make_allocator(type_))
215
+ if restype is Void:
216
+ pass
217
+ elif _winrt.is_receivearray_class(restype):
218
+ argtypes.append(POINTER(UInt32))
219
+ argtypes.append(POINTER(POINTER(get_args(restype)[0])))
220
+ elif is_generic_alias(restype):
221
+ argtypes.append(POINTER(get_origin(restype)))
222
+ else:
223
+ argtypes.append(POINTER(restype))
224
+ closure = partial(
225
+ self._winrt_callback_error_check, getattr(self._owner, method._prototype.__name__), restype, hints
226
+ )
227
+ thunk = WINFUNCTYPE(HRESULT, c_void_p, *argtypes)(closure)
228
+ self._keep_reference_in_python_world_.append(thunk)
229
+ return cast(thunk, c_void_p)
230
+
231
+ # allocate winrt runtime class without constructor.
232
+ def _make_allocator(self, t):
233
+ if is_generic_alias(t) or issubclass(t, ComPtr):
234
+ return type(c_void_p)("Allocator", (c_void_p,), {"__new__": lambda _: t(own=False)})
235
+ return t
236
+
237
+ def _com_callback_error_check(self, callback, this, *args):
238
+ try:
239
+ return callback(*args)
240
+ except Exception as exc:
241
+ logger.exception(f"Unhandled exception caught: {callback}{args}")
242
+ set_error_info(f"{exc.__class__.__name__}: {exc}")
243
+ return E_FAIL
244
+
245
+ def _winrt_callback_error_check(self, callback, restype, hints, this, *args):
246
+ try:
247
+ self._winrt_callback(callback, restype, hints, this, args)
248
+ return S_OK
249
+ except Exception as exc:
250
+ logger.exception(f"Unhandled exception caught: {callback}{args}")
251
+ RoOriginateError(E_FAIL, hstr(f"{exc.__class__.__name__}: {exc}", own=True))
252
+ return E_FAIL
253
+
254
+ def _winrt_callback(self, callback, restype, hints, this, args):
255
+ args = list(args)
256
+ with ExitStack() as exitstack:
257
+ pyargs = []
258
+ for type_ in hints.values():
259
+ self._add_argument(type_, args, pyargs, exitstack)
260
+ result = callback(*pyargs)
261
+ self._handle_result(restype, args, result)
262
+
263
+ def _add_argument(self, type_: type, args: list[Any], pyargs: list[Any], exitstack) -> None:
264
+ if _winrt.is_passarray_class(type_):
265
+ exitstack.enter_context(_winrt.PassArrayCallback(get_args(type_)[0], args.pop(0), args.pop(0), pyargs))
266
+ elif _winrt.is_fillarray_class(type_):
267
+ exitstack.enter_context(_winrt.FillArrayCallback(get_args(type_)[0], args.pop(0), args.pop(0), pyargs))
268
+ elif _winrt.is_receivearray_class(type_):
269
+ exitstack.enter_context(_winrt.ReceiveArrayCallback(get_args(type_)[0], args.pop(0), args.pop(0), pyargs))
270
+ elif type_ is hstr:
271
+ pyargs.append(str(args.pop(0)))
272
+ else:
273
+ pyargs.append(args.pop(0))
274
+
275
+ def _handle_result(self, restype: type, args: list[Any], result: Any) -> Any:
276
+ if restype is Void:
277
+ pass
278
+ elif _winrt.is_receivearray_class(restype):
279
+ return_length, return_pointer = args
280
+ _winrt.ReceiveArrayCallback.handle_result(get_args(restype)[0], return_length, return_pointer, result)
281
+ elif restype is hstr:
282
+ return_pointer = args[0]
283
+ return_pointer[0] = hstr(result)
284
+ elif is_com_class(restype):
285
+ return_pointer = args[0]
286
+ if result:
287
+ result.AddRef()
288
+ return_pointer[0] = result
289
+ else:
290
+ return_pointer = args[0]
291
+ return_pointer[0] = result
292
+
293
+
294
+ class ISelf(IUnknown):
295
+ _iid_ = Guid("{18320492-860a-4c7b-ad7c-6cd65c88c09e}")
296
+
297
+ @commethod(3)
298
+ def GetSelf(self) -> py_object: ...