Markus Hubig wrote, On 4/10/2010 8:31 AM:
On Fri, Apr 9, 2010 at 11:05 PM, Greg Antal <greg.an...@ata-e.com> wrote:
The beauty of using the early binding file is that you don't have to use all that Dispatch syntax because the file does that for you. I don't know what you named this file, but let's say you call it "PyMemtool.py". Now your code just looks like this:

import PyMemtool

fm = PyMemtool.SMTMemtool()
fs = fm.GetFlashModByName("MyFM")

Ahh ok yes ... makes sence. I was looking for some documentation and found a snipplet of "Python Programming on Win32" by Mark Hammond & Andy Robinson witch states, I thought, that the early binding files are just some kind of a "cache file" ... 

That should be all you have to do, but looking at your file I think you'll also have to add an explicit type cast to the class you want:

fs = PyMemtool.DISMTFlashMod (fs)

OK so I can't make my own FlashMod Object, instead I use the SMTMemtool Object to create one. But why do the type cast? After the casting the fs object is no longer a "CoClassBaseClass" it's now a "DispatchBaseClass", am I right?
Actually, the way your PyMemtool.py file is defined, I think the original "fs" will be a generic COM object. The next-to-last line of the GetFlashModByName method definition is

ret = Dispatch(ret, u'GetFlashModByName', None)

That method is supposed to return a FlashMod object, so I think it should look like this:

ret = Dispatch(ret, u'GetFlashModByName', '{661A8843-7984-11D2-9C7F-006097804445}')

If you edit the PyMemtool.py file to look like that, the object returned should actually be of type DISMTFlashMod. And of course, if you do the typecast, it will certainly have that type.

This may not actually be a problem. The way COM works, if you try to invoke FlashMod methods on the generic COM object, COM will try to find an object that can do what you're asking. As long as the FlashMod methods don't try anything fancy like using output ("ByRef") parameters, it will work. But this is just like not doing early binding for the FlashMod object.
 
Hmm it's not that easy finding good documentation for Python-win32! A lot of the stuff I found seems to be rather old and maybe outdated ... Is there some must read documentation about the Python-Win32-COM Stuff out there you can recommend?
The entire chapter 12 of the book you mentioned is available at
http://oreilly.com/catalog/pythonwin32/chapter/ch12.html
I found this indispensable. I tried to find the book at several local book stores (I like going to physical book stores more than on-line stores; I'm old-fashioned that way), but none of them had it. One of the people monitors this mailing list, Tim Golden, has a really useful "how-to" page at
http://timgolden.me.uk/python/win32_how_do_i/
Other than that, I just check with this mailing list and its archives.

- Greg Antal

- Markus

_______________________________________________ python-win32 mailing list python-win32@python.org http://mail.python.org/mailman/listinfo/python-win32


_______________________________________________
python-win32 mailing list
python-win32@python.org
http://mail.python.org/mailman/listinfo/python-win32

Reply via email to