Skip to content

Commit

Permalink
Fix str conversion error of PassArrayCallback
Browse files Browse the repository at this point in the history
  • Loading branch information
ynkdir committed Jan 2, 2025
1 parent bb2a9e6 commit 20baee1
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 2 deletions.
35 changes: 34 additions & 1 deletion tests/test_winrt.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,25 @@
from concurrent.futures import Future
from pathlib import Path

from win32more import FAILED, POINTER, WINFUNCTYPE, Byte, Int32, UInt32, VoidPtr, WinError, cast, pointer
from win32more import (
FAILED,
POINTER,
WINFUNCTYPE,
Byte,
Guid,
Int32,
UInt32,
VoidPtr,
WinError,
cast,
pointer,
)
from win32more._winrt import (
ComClass,
MulticastDelegateImpl,
PassArray,
ReceiveArray,
WinRT_String,
_ro_get_parameterized_type_instance_iid,
box_value,
unbox_value,
Expand Down Expand Up @@ -96,6 +111,24 @@ async def winrt_readlines():
lines10 = [ivector.GetAt(i) for i in range(10)]
self.assertEqual(lines10, lines[0:10])

def test_passarray_convert_hstring_to_str(self):
class IMock(IInspectable):
_classid_ = "IMock"
_iid_ = Guid("{00000000-0000-0000-0000-000000000000}")

@winrt_commethod(6)
def f(self, p: PassArray[WinRT_String]) -> WinRT_String: ...

class Mock(ComClass, IMock):
def f(self, p: list[str]) -> str:
return p[0]

mock = Mock().as_(IMock)

# winrt call: mock.f(["str"]) -> WinrtMethod([hstring])
# winrt callback: vtbl.f([hstring]) -> Mock.f(["str"])
self.assertEqual(mock.f(["hello"]), "hello")

def test_receivearray_param(self):
inarray = [1, 2, 3]

Expand Down
2 changes: 1 addition & 1 deletion win32more/_winrt.py
Original file line number Diff line number Diff line change
Expand Up @@ -386,7 +386,7 @@ def __init__(self, type_, size, ptr):
self._lst = []
for i in range(size):
if type_ is WinRT_String:
self._lst.append(_windows_create_string(ptr[i]))
self._lst.append(_windows_get_string_raw_buffer(ptr[i]))
else:
self._lst.append(ptr[i])

Expand Down

0 comments on commit 20baee1

Please sign in to comment.