Thanks Thomas, appreciate your feedback and suggestions. I cannot
re-implement ReadPacket, so I will just modify the generated file directly.
On Fri, Sep 4, 2009 at 1:32 PM, Thomas Heller <thel...@ctypes.org> wrote:
> px schrieb:
> > Hi there,
> >
> > Is there a way I can change a generated typelib dynamically without
> having
> > to modify the generated .py file itself? (ie. the files generated in
> > C:\Python25\Lib\site-packages\comtypes\gen).
>
> No, not really. The _methods_ list is processed when the class is created,
> later changes to _methods_ have no effect. The processing occurrs in
> _cominterface_meta._make_methods_, in comtypes\__init__.py line 608.
>
> In principle, you could extract code from that function and change the
> generated
> COM method, but I wouldn't recommend that.
>
> Can't you modify the generated file and be done? Must it be regenerated
> more than once?
>
> > In particular I just want to
> > change the signature of one of the methods. I tried this:
> >
> > import comtypes.gen.MyLib as MyLib
> >
> > MyLib.Channel._methods_[3] = comtypes.COMMETHOD([], HRESULT,
> 'ReadPacket',
> > ( ['in'], POINTER(c_ubyte),
> > 'data' ),
> > ( ['in'], c_int, 'length'
> ),
> > ( ['out'], POINTER(c_int),
> > 'actual' ))
> >
> > But it seems like comtypes doesn't "see" or "register" this change.
> > Although if I "print MyLib.Channel._methods_[3]" I see it is changed
> > accordingly. Of course if I make this change in the typelib file
> directly
> > it works.
> >
>
> Another approach would be that you write a new implementation of the
> ReadPacket function, and assign that to the class before you are using it,
> like so:
>
> import comtypes.gen.MyLib as MyLib
>
> def MyReadPacket(self, ...):
> ....
>
> MyLib.Channel.ReadPacket = MyReadPacket
>
> Would that work?
>
> --
> Thanks,
> Thomas
>
>
>
> ------------------------------------------------------------------------------
> 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
>
------------------------------------------------------------------------------
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