Thanks Thomas.  I tried your suggestion and changed out to in but it seems
to not expect a pointer

  COMMETHOD([], HRESULT, 'Read',
            ( ['in'], POINTER(c_ubyte), 'data' ),
             ( ['in'], c_int, 'len' ),
            ( ['out'], POINTER(c_int), 'actual' )),
   ...]

--

data = POINTER(c_ubyte)()
len = 2
res = y.Read(byref(data), len)

ArgumentError: argument 1: <type 'exceptions.TypeError'>: expected
LP_c_ubyte instance instead of pointer to LP_c_ubyte



On Wed, Jun 17, 2009 at 2:06 AM, Thomas Heller <thel...@ctypes.org> wrote:

> px schrieb:
> > Thanks Thomas! This was very helpful indeed.  Working great now :)
> >
> > Came across another problem trying to read back an unsigned byte buffer..
> > I'm pretty stumped
> >
> > #    COMMETHOD([], HRESULT, 'Read',
> > #              ( ['out'], POINTER(c_ubyte), 'data' ),
> > #              ( ['in'], c_int, 'len' ),
> > #              ( ['out'], POINTER(c_int), 'actual' )),
> >
> > When I call Read(2048), I always just get 13 back for the data field
> (first
> > element in returned tuple) but I actually expect more bytes.
> >
> > I took a shot at doing a ctypes style call, but when I try to make the
> call
> >   x.Read(byref(data), len, byref(actual))
> > I get
> >   TypeError: call takes exactly 2 arguments (4 given)
> >
> > It seems that comtypes only wants the in 'len' parameter.
> >
> >>From the IDL:
> >     HRESULT Read(
> >         [out, size_is(length), length_is(*actual)] BYTE* data,
> >         [in] long length,
> >         [out] long* actual);
>
> comtypes isn't able to handle the 'length_is(...)' attribute.  Besides,
> the info from this attribute isn't present in the TLB at all.  So,
> you should override the generated 'Read' method in this way,
> which passes the pointer as 'in' argument, and later unpacks it:
>
>
>   COMMETHOD([], HRESULT, 'Read',
>             ( ['in'], POINTER(c_ubyte), 'data' ),
>              ( ['in'], c_int, 'len' ),
>             ( ['out'], POINTER(c_int), 'actual' )),
>    ...]
>
>   def Read(self, len):
>       data = POINTER(c_ubyte)()
>       actual = self._Read(byref(data), len)
>       result = data[:actual]
>       # I guess you need to free the memory here?
>       # windll.ole32.CoTaskMemFree(data)
>       return result
>
> Thomas
>
>
>
> ------------------------------------------------------------------------------
> Crystal Reports - New Free Runtime and 30 Day Trial
> Check out the new simplified licensing option that enables unlimited
> royalty-free distribution of the report engine for externally facing
> server and web deployment.
> http://p.sf.net/sfu/businessobjects
> _______________________________________________
> comtypes-users mailing list
> comtypes-users@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/comtypes-users
>
------------------------------------------------------------------------------
Crystal Reports - New Free Runtime and 30 Day Trial
Check out the new simplified licensing option that enables unlimited
royalty-free distribution of the report engine for externally facing 
server and web deployment.
http://p.sf.net/sfu/businessobjects
_______________________________________________
comtypes-users mailing list
comtypes-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/comtypes-users

Reply via email to