Skip to content

Commit 3be4f69

Browse files
authored
Implement record pointers as [in, out] method parameters of a Dispatch Interface (#2310)
* Implement record pointers as method parameters of a Dispatch Interface to get server side modifications of a record marshaled back to the client. * Added a untitest for record pointers as [ in, out ] method parameters.
1 parent 636e4c0 commit 3be4f69

File tree

6 files changed

+25
-1
lines changed

6 files changed

+25
-1
lines changed

com/TestSources/PyCOMTest/PyCOMImpl.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -618,6 +618,14 @@ HRESULT CPyCOMTest::GetStruct(TestStruct1 *ret)
618618
*ret = r;
619619
return S_OK;
620620
}
621+
622+
HRESULT CPyCOMTest::ModifyStruct(TestStruct1 *prec)
623+
{
624+
prec->int_value = 100;
625+
prec->str_value = SysAllocString(L"Nothing is as constant as change");
626+
return S_OK;
627+
}
628+
621629
HRESULT CPyCOMTest::DoubleString(BSTR in, BSTR *out)
622630
{
623631
*out = SysAllocStringLen(NULL, SysStringLen(in) * 2);

com/TestSources/PyCOMTest/PyCOMImpl.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,8 @@ class CPyCOMTest : public IDispatchImpl<IPyCOMTest, &IID_IPyCOMTest, &LIBID_PyCO
119119
STDMETHOD(None)();
120120
STDMETHOD(def)();
121121

122+
STDMETHOD(ModifyStruct)(TestStruct1 *prec);
123+
122124
// info associated to each session
123125
struct PyCOMTestSessionData {
124126
IStream *pStream; // Stream for marshalling the data to the new thread.

com/TestSources/PyCOMTest/PyCOMTest.idl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -293,6 +293,8 @@ library PyCOMTestLib
293293
// reserved words etc
294294
HRESULT None();
295295
HRESULT def();
296+
// Test struct byref as [ in, out ] parameter.
297+
HRESULT ModifyStruct([ in, out ] TestStruct1 * prec);
296298
};
297299

298300
// Define a new class to test how Python handles derived interfaces!

com/win32com/client/build.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -548,7 +548,6 @@ def _ResolveType(typerepr, itypeinfo):
548548
if was_user and subrepr in [
549549
pythoncom.VT_DISPATCH,
550550
pythoncom.VT_UNKNOWN,
551-
pythoncom.VT_RECORD,
552551
]:
553552
# Drop the VT_PTR indirection
554553
return subrepr, sub_clsid, sub_doc

com/win32com/src/oleargs.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1572,6 +1572,7 @@ BOOL PythonOleArgHelper::MakeObjToVariant(PyObject *obj, VARIANT *var, PyObject
15721572
// Nothing else to do - the code below sets the VT up correctly.
15731573
break;
15741574
case VT_RECORD:
1575+
case VT_RECORD | VT_BYREF:
15751576
rc = PyObject_AsVARIANTRecordInfo(obj, var);
15761577
break;
15771578
case VT_CY:

com/win32com/test/testPyComTest.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,18 @@ def TestCommon(o, is_generated):
198198
progress("Checking structs")
199199
r = o.GetStruct()
200200
assert r.int_value == 99 and str(r.str_value) == "Hello from C++"
201+
# Dynamic does not support struct byref as [ in, out ] parameters
202+
if hasattr(o, "CLSID"):
203+
progress("Checking struct byref as [ in, out ] parameter")
204+
mod_r = o.ModifyStruct(r)
205+
# We expect the input value to stay unchanged
206+
assert r.int_value == 99 and str(r.str_value) == "Hello from C++"
207+
# and the return value to reflect the modifications performed on the COM server side
208+
assert (
209+
mod_r.int_value == 100
210+
and str(mod_r.str_value) == "Nothing is as constant as change"
211+
)
212+
201213
assert o.DoubleString("foo") == "foofoo"
202214

203215
progress("Checking var args")

0 commit comments

Comments
 (0)