Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement record pointers as [in, out] method parameters of a Dispatch Interface #2310

Merged
merged 3 commits into from
Oct 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions com/TestSources/PyCOMTest/PyCOMImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -618,6 +618,14 @@ HRESULT CPyCOMTest::GetStruct(TestStruct1 *ret)
*ret = r;
return S_OK;
}

HRESULT CPyCOMTest::ModifyStruct(TestStruct1 *prec)
{
prec->int_value = 100;
prec->str_value = SysAllocString(L"Nothing is as constant as change");
return S_OK;
}

HRESULT CPyCOMTest::DoubleString(BSTR in, BSTR *out)
{
*out = SysAllocStringLen(NULL, SysStringLen(in) * 2);
Expand Down
2 changes: 2 additions & 0 deletions com/TestSources/PyCOMTest/PyCOMImpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,8 @@ class CPyCOMTest : public IDispatchImpl<IPyCOMTest, &IID_IPyCOMTest, &LIBID_PyCO
STDMETHOD(None)();
STDMETHOD(def)();

STDMETHOD(ModifyStruct)(TestStruct1 *prec);

// info associated to each session
struct PyCOMTestSessionData {
IStream *pStream; // Stream for marshalling the data to the new thread.
Expand Down
2 changes: 2 additions & 0 deletions com/TestSources/PyCOMTest/PyCOMTest.idl
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,8 @@ library PyCOMTestLib
// reserved words etc
HRESULT None();
HRESULT def();
// Test struct byref as [ in, out ] parameter.
HRESULT ModifyStruct([ in, out ] TestStruct1 * prec);
};

// Define a new class to test how Python handles derived interfaces!
Expand Down
1 change: 0 additions & 1 deletion com/win32com/client/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -545,7 +545,6 @@ def _ResolveType(typerepr, itypeinfo):
if was_user and subrepr in [
pythoncom.VT_DISPATCH,
pythoncom.VT_UNKNOWN,
pythoncom.VT_RECORD,
]:
# Drop the VT_PTR indirection
return subrepr, sub_clsid, sub_doc
Expand Down
1 change: 1 addition & 0 deletions com/win32com/src/oleargs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1572,6 +1572,7 @@ BOOL PythonOleArgHelper::MakeObjToVariant(PyObject *obj, VARIANT *var, PyObject
// Nothing else to do - the code below sets the VT up correctly.
break;
case VT_RECORD:
case VT_RECORD | VT_BYREF:
rc = PyObject_AsVARIANTRecordInfo(obj, var);
break;
case VT_CY:
Expand Down
12 changes: 12 additions & 0 deletions com/win32com/test/testPyComTest.py
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,18 @@ def TestCommon(o, is_generated):
progress("Checking structs")
r = o.GetStruct()
assert r.int_value == 99 and str(r.str_value) == "Hello from C++"
# Dynamic does not support struct byref as [ in, out ] parameters
if hasattr(o, "CLSID"):
progress("Checking struct byref as [ in, out ] parameter")
mod_r = o.ModifyStruct(r)
# We expect the input value to stay unchanged
assert r.int_value == 99 and str(r.str_value) == "Hello from C++"
# and the return value to reflect the modifications performed on the COM server side
assert (
mod_r.int_value == 100
and str(mod_r.str_value) == "Nothing is as constant as change"
)

assert o.DoubleString("foo") == "foofoo"

progress("Checking var args")
Expand Down
Loading