Thomas,

Thanks for the help.

I do not seem to be able to successfully call the method self._GetPos() - 
Python generates an AttributeError.

I have however managed to get something to work.

I edited the 'Positions' parameter to be an input in the generated python ( see 
below ).

COMMETHOD([dispid(6), helpstring(u'method GetPos')], HRESULT, 'GetPos',
              ( ['in'], POINTER(c_double), 'Positions' ),
              ( ['in'], c_int, 'Size' ),
              ( ['retval', 'out'], POINTER(c_int), 'pReturnedSize' )),

I then wrote a wrapper function as below.

def My_GetPos(self,size):
Positions  = ( c_double * size )()
Positions2= cast( Positions, POINTER(c_double) )
returned_size = m.GetPos(Positions2,3)
return Positions2(:returned_size)

Regards,

Calum....





________________________________
From: Thomas Heller <thel...@ctypes.org>
To: comtypes-users@lists.sourceforge.net
Sent: Fri, 7 May, 2010 19:49:15
Subject: Re: [comtypes-users] [out, size_is(Size)] problem

Calum McLean schrieb:
> Hi,
> 
> I have a method from some 3rd party COM with the following IDL description.
> 
> [id(6), helpstring("method GetPos")] HRESULT GetPos([out, size_is(Size)] 
> double* Positions, [in] long Size, [out, retval] long * pReturnedSize);
> 
> I can't seem to work out what syntax I should use to return the 'Positions' 
> data.  
> 
> The kind of thing I have tried is as follows:-
> 
> (pos,rs) = m.GetPos(3)
> 
> rs is returned correctly.
> pos is just a single element.

comtypes cannot handle this signature automatically for various reasons.
At least one reason is that the 'size_is(Size)' attribute is present in the
IDL but not in the type library that comtypes uses to generate the wrapper code.

You must implement the GetPos() method yourself in the generated interface 
class.
It should call the low-level, normally invisible, automatically generated
_GetPos method with arguments that you create yourself.

class ...:

    def GetPos(self, size):
        returned_size = c_long()
        positions = (c_double * size)()
        self._GetPos(byref(positions), size, byref(returned_size))
        return positions[:returned_size.value]

Thomas

------------------------------------------------------------------------------

_______________________________________________
comtypes-users mailing list
comtypes-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/comtypes-users



      
------------------------------------------------------------------------------

_______________________________________________
comtypes-users mailing list
comtypes-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/comtypes-users

Reply via email to