Mustafa Görmezer schrieb: > Hello, > > I am automating a CAD System which expects a so called > CATSafeArrayVariant. This is defined as one-dimensional arrays of > CATVariants. When I am right, this should work now with comtypes. But > how do I use it when a method expects it by reference ?
Can you post the IDL definition of the method, please? And the code that the generated wrapper has for the method, from the file that is generated in the comtypes\gen directory? > In pure Python (where no "by reference" exists) I would simply use this > to get a list of file names: > > myrefs = Send.GetListOfDependantFiles() > > In VB (which works) it looks like: > > Dim arrayOfVariantOfBSTR() > ReDim arrayOfVariantOfBSTR(500) > Call Send.GetListOfDependantFiles(arrayOfVariantOfBSTR) > > After this I can find the results in the arrayOfVariantOfBSTR, which can > be used in a for each loop. > > I found the test_safearray.py in the comtypes package and tried this: > > myrefs = _midlSAFEARRAY(POINTER(IUnknown)) > newrefs = Send.GetListOfDependantFiles(t) > > But this gives me an AttributeError ?! Can someone help ? I am unsure if this snippet will help you, but at least it shows how to create a SAFEARRAY containing three NULL IUnknown pointers: c:\svn\theller\comtypes>py25 Python 2.5.2 (r252:60911, Feb 21 2008, 13:11:45) [MSC v.1310 32 bit (Intel)] on win32 Type "help", "copyright", "credits" or "license" for more information. >>> from ctypes import POINTER >>> from comtypes import IUnknown >>> from comtypes.automation import _midlSAFEARRAY >>> typ = _midlSAFEARRAY(POINTER(IUnknown)) # typ is now a SAFEARRAY type that contains IUnknown pointers: >>> typ <class 'ctypes.LP_SAFEARRAY_POINTER(IUnknown)'> # You have to create an instance of this type by calling the .from_param class method, passing one argument (a sequence of objects that are or can be converted to IUnknown pointers): >>> inst = typ.from_param([None, None, None]) # Dereferencing (indexing with 0) the instance unpacks the safearray, # it returns three NULL IUnknown pointers: >>> inst[0] (<POINTER(IUnknown) ptr=0x0 at bf62b0>, <POINTER(IUnknown) ptr=0x0 at bf6300>, <POINTER(IUnknown) ptr=0x0 at bf6350>) >>> The calls that you have to make are a little bit strange, this is because normally the comtypes code calls them when you pass parameters to a COM method call. Thomas ------------------------------------------------------------------------- This SF.net email is sponsored by the 2008 JavaOne(SM) Conference Don't miss this year's exciting event. There's still time to save $100. Use priority code J8TL2D2. http://ad.doubleclick.net/clk;198757673;13503038;p?http://java.sun.com/javaone _______________________________________________ comtypes-users mailing list comtypes-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/comtypes-users