[python-win32] Dispatches With Events on COM Object

Neil Benn benn at cenix-bioscience.com
Thu Aug 3 12:49:14 CEST 2006


Mark Hammond wrote:
> <snip>
> The problem will be that the object itself doesn't supply the typeinfo
> necessary to associate the object with the makepy generated class.  It
> should however be possible for you to manually extract a suitable object
> though.
>
> What you need is something like:
>
> from win32com.client import gencache
> mod = gencache.EnsureModule(...) # use 'makepy -i' to see the params
> ob = mod.Application()
> objCybio = win32com.client.DispatchWithEvents(ob, CybioEvents)
>
> <snip>
>   
Hello,

          Hmm the type info looks like an issue, the new code is now:

mod = gencache.EnsureModule('{A4818FD5-6479-11D4-8452-00104B92DD56}', 0, 
1, 0)
print dir(mod)
ob = mod.Application
objCybio = win32com.client.DispatchWithEvents(ob, CybioEvents)

--
This now gives me the following error:

Traceback (most recent call last):
  File "C:\Program 
Files\Python24\Lib\site-packages\pythonwin\pywin\framework\scriptutils.py", 
line 310, in RunScript
    exec codeObject in __main__.__dict__
  File "C:\Documents and Settings\benn\Desktop\cybio test.py", line 15, in ?
    objCybio = win32com.client.DispatchWithEvents(ob, CybioEvents)
  File "C:\Program 
Files\Python24\Lib\site-packages\win32com\client\__init__.py", line 243, 
in DispatchWithEvents
    disp = Dispatch(clsid)
  File "C:\Program 
Files\Python24\Lib\site-packages\win32com\client\__init__.py", line 96, 
in Dispatch
    return __WrapDispatch(dispatch, userName, resultCLSID, typeinfo, 
UnicodeToString, clsctx)
  File "C:\Program 
Files\Python24\Lib\site-packages\win32com\client\__init__.py", line 44, 
in __WrapDispatch
    return dynamic.Dispatch(dispatch, userName, WrapperClass, typeinfo, 
UnicodeToString=UnicodeToString,clsctx=clsctx)
  File "C:\Program 
Files\Python24\Lib\site-packages\win32com\client\dynamic.py", line 111, 
in Dispatch
    typeinfo = IDispatch.GetTypeInfo()
AttributeError: class Application has no attribute 'GetTypeInfo'

    Interestingly, the printout of dir(mod) gives me:

['Application', 'CLSID', 'CLSIDToClassMap', 'CLSIDToPackageMap', 
'CoClassBaseClass', 'Dispatch', 'DispatchBaseClass', 'IApplication', 
'IApplicationEvents', 'IApplicationEvents_vtables_', 
'IApplicationEvents_vtables_dispatch_', 'IDocumentEvents', 
'IDocumentEvents_vtables_', 'IDocumentEvents_vtables_dispatch_', 'IID', 
'LCID', 'LibraryFlags', 'MajorVersion', 'MinorVersion', 'NamesToIIDMap', 
'RecordMap', 'VTablesToClassMap', 'VTablesToPackageMap', '__builtins__', 
'__doc__', '__file__', '__name__', '_in_gencache_', 
'defaultNamedNotOptArg', 'defaultNamedOptArg', 'defaultUnnamedArg', 
'makepy_version', 'python_version', 'pythoncom', 'win32com']

    For completeness, I've attached the generated file from makepy (the 
above test was done without this present).  I've done some playing 
around, if I do a simlpe dispatch (without events) the makepy file does 
not get compiled to a pyc but the __init__ does.

    Any thoughts?

    Thanks for any and all help/advice.

Cheers,

Neil

-- 
Neil Benn MSc
Head of Automation
Cenix BioScience GmbH
Tatzberg 47
01307 Dresden
Germany

http://wwww.cenix-bioscience.com

-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: A4818FD5-6479-11D4-8452-00104B92DD56x0x1x0.py
Url: http://mail.python.org/pipermail/python-win32/attachments/20060803/fe1b2a51/attachment.asc 


More information about the Python-win32 mailing list