Pythoncom: Using array of special type (com_struct) as parameter

UlleAcki ulf.ackermann at pdv.de
Wed Sep 15 12:06:31 EDT 2004


Hi,
in my Python program I have to use a COM-Server. One method of the COM
class needs a SAFEARRAY of a special type as parameter.
Trying to create such an array and calling the method results in a
MemoryError.
Is it possible with pythoncom to use a SAFEARRAY(<mytype>)* as
parameter? If yes, how can I achieve this?

Thanks in advance, Ulf


Code pieces for demonstration:

    IDL ------------
    typedef [uuid(XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX)]
    struct tagStructure {
        BSTR name;
        IUnknown* interface;
    } SStructure;

    [ odl, uuid(XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX), 
                dual, oleautomation ]
    interface IManager : IDispatch {
        [id(0x00000001)]
        HRESULT Init([in] long id, 
                     [in] SAFEARRAY(SStructure)* psaInterface);
    };

    Python ---------
    modtypelib = win32com.client.gencache.EnsureModule('{XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX}',
0, 1, 0)

    mgr = win32com.client.Dispatch("ProgId")
    obj = win32com.client.Dispatch("ProgId-2")
    iUnk = obj._oleobj_.QueryInterface(pythoncom.IID_IUnknown)

    rec = win32com.client.Record('SStructure', mgr)
    rec.name = 'TheName'
    rec.interface = iUnk
    arr = []
    arr.append(rec)
    mgr.Init(1, arr)

    --> MemoryError: CreatingSafeArray



More information about the Python-list mailing list