In case somebody has the same issue and stumbles into this thread I will answer my own question.

With the current release (306) of pywin32 it is not possible to create a COM Record and assign a value of type SAFEARRAY(VT_RECORD) to one of the record fields.

I have opened a pull request on github ( https://github.com/mhammond/pywin32/pull/2317 ) to add this functionality.

Cheers,

Thomas

On 2024-07-23  07:42 a.m. , Thomas Geppert wrote:
Is it currently somehow possible to create a COM Record and assign a value of type SAFEARRAY(VT_RECORD) to one of the record fields?

I'm dealing with a COM interface that defines a COM Record of the following type in the IDL-file.

    typedef [uuid(xxxxx)]
    struct tagT_RECORD_A {
        SAFEARRAY(T_RECORD_B) array_of_records;
        <some-more-simple-type-fields>
    } T_RECORD_A

The 'T_RECORD_B' is another COM Record type with fields of just simple types.

I didn't find a way to assign the required SAFEARRAY instance to the 'array_of_records' field of a 'T_RECORD_A' instance.

When I run:

    import pythoncom
    import win32.client
    from win32com.client import gencache, Record

    mod = gencache.EnsureModule('{XXXXX}', X, Y, Z)
    comp = win32com.client.Dispatch("SomeProgID", clsctx=pythoncom.CLSCTX_LOCAL_SERVER)
    rec_a = Record("T_RECORD_A", comp)
    rec_b_1 = Record("T_RECORD_B", comp)
    rec_b_3 = Record("T_RECORD_B", comp)

it successfully creates all record instances. However, assigning to the 'array_of_records' field of the 'T_RECORD_A' instance
raises an exception:

    rec_a.array_of_records = [rec_b_1, rec_b_2]
        com_error: (-2147024809,  'The parameter is incorrect.', None, None)

From what I can tell by skimming through the code, it looks like pywin32 is creating a SAFEARRAY(VT_VARIANT) with VARIANT elements of type VT_RECORD while the COM-server expects a SAFEARRAY(VT_RECORD), i.e. COM Record elements.


Cheers,

Thomas

_______________________________________________
python-win32 mailing list
python-win32@python.org
https://mail.python.org/mailman/listinfo/python-win32
_______________________________________________
python-win32 mailing list
python-win32@python.org
https://mail.python.org/mailman/listinfo/python-win32

Reply via email to