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

Reply via email to