This will be due to the object throwing an incorrect error code when the
flag for the method is incorrect, and win32com can't know what the correct
flag is ahead of time for "dynamic" objects.

Further, the object doesn't support type info from its typelib at runtime,
so Python can't match up the makepy generated module with the object, which
would also prevent this.  It might be possible to work around that with
something like:

from win32com.client import gencache
mod = gencache.EnsureModule('{A5B37030-06D9-11D2-A58A-006097B17A75}', 0, 4,
0)
gui = win32com.client.Dispatch("ReqPro40.GUIApp")

# according to your snippet, the generated file has a class
# IReqProGUIApp - convert the "dynamic" object to one of them.
gui = mod.IReqProGUIApp(gui)

gui.ShowWord() # should work as it goes directly by the generated method.

Sadly, it will be necessary to wrap *every* object - eg, imagine a method
GetFoo() that returned an object, you would need:

  foo = gui.GetFoo()
  foo = mod.IReqWhateverFooIs(foo)
  # obviously can be written as 1 line ;)

Hope this helps,

Mark

> -----Original Message-----
> From: [EMAIL PROTECTED] [mailto:python-win32-
> [EMAIL PROTECTED] On Behalf Of Reedick, Andrew
> Sent: Thursday, 24 July 2008 12:42 AM
> To: python-win32@python.org
> Subject: [python-win32] Problem with TLB file and COM
> 
> I'm having trouble with a COM object for which none of its methods are
> available at runtime.  The COM class is defined in a tlb file.  I used
> "makepy -i", added the gencache lines to the program, and can see the
> methods in the generated file.  However, when I try to call any method,
> it blows up with a DISPATCH_METHOD flag error.
> 
> The equivalent code works just fine in Perl.
> 
> Anyone have any idea why a COM object defined in a tlb file would be so
> problematic in Python?
> 
> 
> === program ===
> import win32com.client
> 
> from win32com.client import gencache
> gencache.EnsureModule('{A5B37030-06D9-11D2-A58A-006097B17A75}', 0, 4,
> 0)
> 
> gui = win32com.client.Dispatch("ReqPro40.GUIApp")
> print gui
> print
> print dir(gui)
> 
> print
> print 'showword =', gui.ShowWord()
> 
> 
> 
> == output ==
> <COMObject ReqPro40.GUIApp>
> 
> ['_ApplyTypes_', '_FlagAsMethod', '_LazyAddAttr_', '_NewEnum',
> '_Release_', '__AttrToID__', '__LazyMap__', '__call__', '__cmp__',
> '__doc__', '__getattr__', '__getitem__', '__init__', '__int__',
> '__len__', '__module__', '__nonzero__', '__repr__', '__setattr__',
> '__setitem__', '__str__', '_builtMethods_', '_enum_',
> '_find_dispatch_type_', '_get_good_object_',
> '_get_good_single_object_',
> '_lazydata_', '_make_method_', '_mapCachedItems_', '_oleobj_',
> '_olerepr_', '_print_details_', '_proc_', '_unicode_to_string_',
> '_username_', '_wrap_dispatch_']
> 
> showword =
> Traceback (most recent call last):
>   File "D:\mydata\dev\reqpro\renumber\c.py", line 13, in <module>
>     print 'showword =', gui.ShowWord()
>   File "C:\Python25\Lib\site-packages\win32com\client\dynamic.py", line
> 491, in __getattr__
>     raise pythoncom.com_error, details
> pywintypes.com_error: (-2147352567, 'Exception occurred.', (0,
> 'Smalltalk', 'Incorrect dispatch invocation flags: DISPATCH_METHOD flag
> not set for method ShowWord.', None, 0, 0), None)
> 
> 
> === snippets of gen file ====
> 
> CLSID = IID('{A5B37030-06D9-11D2-A58A-006097B17A75}')
> ...
> from win32com.client import DispatchBaseClass
> class IReqProGUIApp(DispatchBaseClass):
>       """RequisitePro GUI Application Dispatch Interface"""
>       CLSID = IID('{52795522-11D4-11D2-A59B-006097B17A75}')
>       coclass_clsid = None
> 
>       ...
> 
>       def ShowWord(self):
>               """Brint the Word Workplace to the front."""
>               return self._oleobj_.InvokeTypes(209, LCID, 1, (11, 0),
> (),)

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

Reply via email to