I'm trying to call a COM method that requires a SafeArray of Strings to be passed as reference, which is then filled up with the method results. This is the code in VBA, which works flawlessly:
dimr RC as New RAS41.HECRASControllerRC.Project_Open "c:\myProj.prj"dim numMessages as Longdim messages() as StringRC.Compute_CurrentPlan( numMessages, messages())
Now, I'm trying to do the same from with Python 3.4, using the win32com module. However, I'm stuck at trying to create the second parameter with the correct type, which according to combrowse.py should be "Pointer SafeArray String".
This was my first attempt:
import win32comRC = win32com.client.Dispatch("RAS41.HECRASController")RC.Project_Open("c:\\myProj.prj")numMessages = 0messages = []RC.Compute_CurrentPlan(numMessages, messages)
I also tried constructing that variable as
messages = win32com.client.VARIANT(pythoncom.VT_ARRAY | pythoncom.VT_BSTR, [])
but it didn't work either. Error messages look like this:
Traceback (most recent call last):File "<pyshell#101>", line 1, in <module> print(o.Compute_CurrentPlan(1,b))File "<COMObject RAS41.HECRASController>", line 3, in Compute_CurrentPlanFile "C:\Python34\lib\site-packages\win32com\client\dynamic.py", line 282, in _ApplyTypes_result = self._oleobj_.InvokeTypes(*(dispid, LCID, wFlags, retType, argTypes) + args)TypeError: Objects for SAFEARRAYS must be sequences (of sequences), or a buffer object.