[Python-au] PythonCom Error

Christian Daldrup Christian.Daldrup at gmx.de
Wed Feb 9 12:20:50 CET 2005


I am new in this mailing list and so first greetings to all users.

I have written a C++ Com Dll (VS 6). In this Dll I declared a struct 
with a SafeArray(double) as a member.

My IDL implementation:
    helpstring("Parameters for Lib") 
struct Params { 
    [helpstring("Distribution")] long lDistribution; 
    [helpstring("Type")] long lType; 
    [helpstring("a CalFlag")] long  lACalFlag; 
    [helpstring("b CalFlag")] long lBCalFlag; 
    [helpstring("c CalFlag")] long lCCalFlag; 
    [helpstring("d CalFlag")] long lDCalFlag; 
    [helpstring("a")] double dA; 
    [helpstring("b")] double dB; 
    [helpstring("c")] double dC; 
    [helpstring("d")] double dD; 
    [helpstring("q")] double dQ; 
    [helpstring("ks")] SAFEARRAY(double) dKs; 
} Params; 

First I created a file with makepy.py
Standard variables like "dA" I can set normally:
import win32com.client
myCom = win32com.client.Dispatch("ComLib.Lib")
rec = win32com.client.Record('Params', myCom)
rec.dA = 3.5 # works fine
rec.dKs = (1.0, 2.0, 3.0 ,4.2, 5.5) # doesn´t work
Error Message:
Traceback (most recent call last): 
File "C:\Visual Studio 6.0\com.py", line 6, in ? 
myStruct.dKs = (1,2,3,4) 
pywintypes.com_error: (-2147024809, 'Falscher Parameter.', None, None)

After this I try to use an array:
import array
a = array.array('d', [1.4, 3.4])
b = buffer(a)
rec.dKs = b
# same error

In VBA I use the same struct, but their I ReDim the SafeArray:
Dim vp As Lib.Params
ReDim vp.dKs(UBound(params, 1))
Call Range2DblArray(params, vp.dKs)

# my vba fill function
Sub Range2DblArray(range As Variant, arr As Variant)
    'ReDim myArray(UBound(range, 1))
    Dim i As Integer
    For i = 1 To UBound(range, 1)
        arr(i) = CDbl(range(i, 1))
    Next i
    'Range2Array = myArray
End Sub

In VB the Code works fine.

Now, I'd like to know, if it is possible to create/resize the dKs tuple in
the com_struct or if I have to implement a function in my DLL which adds
elements to my struct in the DLL?

thank you in advance


DSL Komplett von GMX +++ Supergünstig und stressfrei einsteigen!
AKTION "Kein Einrichtungspreis" nutzen: http://www.gmx.net/de/go/dsl

More information about the python-au mailing list