Hi, Sorry to bring this back up but I'm still stumped, and I feel very close!! Thomas I took your suggestion and changed the 'out' to 'in'.
From: COMMETHOD([], HRESULT, 'Read', ( ['out'], POINTER(c_ubyte), 'data' ), ( ['in'], c_int, 'len' ), ( ['out'], POINTER(c_int), 'actual' )), ...] To: COMMETHOD([], HRESULT, 'Read', ( ['in'], POINTER(c_ubyte), 'data' ), ( ['in'], c_int, 'len' ), ( ['out'], POINTER(c_int), 'actual' )), ...] However defining it this way, it now seems to expect a single c_ubyte instead of a pointer to a c_ubyte. When I try: data = POINTER(c_ubyte)() res = y.Read(byref(data), len) I get this exception, which seems odd since we defined it as POINTER(c_ubyte) in the type library: ctypes.ArgumentError: argument 1: <type 'exceptions.TypeError'>: expected LP_c_ubyte instance instead of pointer to LP_c_ubyte However, when I try: data = c_ubyte() res = y.Read(byref(data), len) then it executes successfully, but of course data only has 1 value and Python crashes after the next Read attempt. I think maybe I need to redefine to something else? Thanks again for your help so far. On Thu, Jun 18, 2009 at 11:57 AM, px<p...@qualm.net> wrote: > 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 > > ------------------------------------------------------------------------------ Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day trial. Simplify your report design, integration and deployment - and focus on what you do best, core application coding. Discover what's new with Crystal Reports now. http://p.sf.net/sfu/bobj-july _______________________________________________ comtypes-users mailing list comtypes-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/comtypes-users