Am 30.01.2010 06:23, schrieb Pablo Bianucci: > Hi! > > I am trying to use an ActiveX control (.OCX, from a piezo electric stage > controller)) from a Python program. I have managed to get the control to work, > but I am having problems calling a method. > > This is the method in question (from the autogenerated typelib): > > === > DISPMETHOD([dispid(20)], c_int, 'GetControlMode', > ( [], c_int, 'lChanID' ), > ( [], POINTER(c_int), 'plMode' )), > === > > This is what I am doing trying to use the method (it should give me an > integer): > > === > mode = 0 > mode_ptr = cast(mode, POINTER(c_int))
What you are doing here is that you create a NULL pointer - which is probably not what you want. But see below. > try: > piezo1.GetControlMode(APTPiezoLib.CHAN1_ID, mode_ptr) > except Exception, e: > print "Exception:", e > === > > And I get: > > === > Exception: Cannot put <comtypes._safearray.LP_c_long object at 0x012D9440> in > VARIANT > ===i > > I have no previous experience with comtypes or ctypes (or Win32 programming, > for that matter ;-)), so I might be doing something stupidly wrong. I've tried > all the permutations I could think of already, so I need expert help. Ok, the interface that you have is a pure dispinterface, which means that all methods of the COM object are eventually called as IDispatch.Invoke() calls. The Invoke() method packs all parameters into a DISPPARAM structure which basically is an array of VARIANT instances. This explains the error that you get - comtypes is trying to pack the POINTER parameter that you have created into a VARIANT. This only works for 'automation-compatible' data types and your pointer is not one of those. I would guess that the 'mode_ptr' argument is an argument that must be passed by reference (this is visual basic speak). Do you have sample VB code that shows how this method is used? However, it could be that comtypes is not able to call this method... Thomas ------------------------------------------------------------------------------ SOLARIS 10 is the OS for Data Centers - provides features such as DTrace, Predictive Self Healing and Award Winning ZFS. Get Solaris 10 NOW http://p.sf.net/sfu/solaris-dev2dev _______________________________________________ comtypes-users mailing list comtypes-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/comtypes-users