I’m trying to access a com object written in C in python script in dynamo. I have successfully managed to load the com object and the function calls seem to work (no errors or exceptions) but when I use the functions with parameters passed by reference, I only ever get zero returned:
t = System.Type.GetTypeFromProgID("myComObject") o = System.Activator.CreateInstance(t) o.Open("afile") <==the com object needs to open a file to be of use aNumber=0 o.GetAValue(0,aNumber);
The signature of the GetAValue function is defined as:
short GetAValue(short value1, short* value2)
The return value indicating success (always zero) and the second parameter being the value i’m interested in.
aNumber is always zero. The exact same script (with only changing the functions to load the com object) when ran using spyder using python 3.6 works just fine and I get a non zero value returned as expected.
Is there something I’m doing wrong here?
EDIT: I have asked the developers of the com object to confirm that the functions are being called as expected. They have debugged the code and have proved that the value is being passed in and set to a non-zero value BUT when it the function returns back to the script, it is being set back to a default value. We have both independently tried passing the value by clr reference and this just throws an error.
s= clr.Reference[int]() o.GetAValue (0,s)
ValueError: Could not convert argument 0 for call to GetAValue