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);
Any thoughts?
Thanks!
Eddie
On Tue, Jun 16, 2009 at 3:08 PM, Thomas Heller <thel...@ctypes.org> wrote:
> px schrieb:
> > I just wanted to add, from more reading, all the examples that point to
> what
> > I want to do seem to involve registering a new class as a COM component.
> > The thing is, I only really want to use this in the same client, as that
> > which dispatched the object. I don't need a server here and would like
> to
> > avoid registering a new COM component just for that purpose. In C++ I
> see
> > this is can be done by simply creating a subclass of ISomeInterface, and
> it
> > seems to work off the bat. You can create an instance of it, and use it
> as
> > needed.
> >
> > Can something similar be done with comtypes? Is registering a COM server
> > the only way to go?
> >
> > Basically I want to do something like this:
> >
> > import comtypes.client as cc
> > import comtypes.gen.ExampleLib
> >
> > class ISomeInterface_Impl(ExampleLib.ISomeInterface):
> > # This is the concrete implementation of ExampleLib.ISomeInterface
> > pass
> >
> > # --
> >
> > # Dispatch the COM application
> > obj = cc.CreateObject(ExampleLib.MainApp)
> >
> > # Create instance of my own implementation of ISomeInterface
> > myimpl = ISomeInterface_Impl()
> >
> > # Here I want to pass my own implementation of ISomeInterface as a
> parameter
> > to a method of MainApp
> > obj.SomeMethod(myimpl)
> >
> >
> > At this point, I'm not sure how I can define the class
> ISomeInterface_Impl
> > to do the above.
>
> Yes, you can do that with comtypes. Define a class that implements the
> methods,
> and derive the class from 'comtypes.COMObject':
>
> class MyImpl(comtypes.COMObject):
> # you must declare the interface(s) that your object implements
> _com_interfaces_ = [ExampleLib.ISomeInterface]
>
> def ISomeInterface_blah(self, ...):
> # whatever
>
> then create an instance:
>
> myimpl = MyImpl()
>
> pass a COM interface pointer from your object to the method of the other
> object:
>
> obj.SomeMethod(myimpl.QueryInterface(ExampleLib.ISomeInterface)
>
>
> That's it, in a nutshell ;-) For writing the method implementations,
> be sure to read the docs about com servers in the web pages. And to debug
> this stuff, you might want to turn logging on, like this (at the top of
> your
> script):
>
> import logging
> logging.basicConfig(level=logging.DEBUG)
>
> 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