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

# -*- coding: mbcs -*-
# Created by makepy.py version 0.4.95
# By python version 2.4.3 (#69, Apr 11 2006, 15:32:42) [MSC v.1310 32 bit 
(Intel)]
# From type library 'Opalctrl.exe'
# On Thu Aug 03 12:42:09 2006
""""""
makepy_version = '0.4.95'
python_version = 0x20403f0

import win32com.client.CLSIDToClass, pythoncom
import win32com.client.util
from pywintypes import IID
from win32com.client import Dispatch

# The following 3 lines may need tweaking for the particular server
# Candidates are pythoncom.Missing, .Empty and .ArgNotFound
defaultNamedOptArg=pythoncom.Empty
defaultNamedNotOptArg=pythoncom.Empty
defaultUnnamedArg=pythoncom.Empty

CLSID = IID('{A4818FD5-6479-11D4-8452-00104B92DD56}')
MajorVersion = 1
MinorVersion = 0
LibraryFlags = 8
LCID = 0x0

from win32com.client import DispatchBaseClass
class IApplication(DispatchBaseClass):
        """IApplication Interface"""
        CLSID = IID('{FC1820B6-691D-11D4-8457-00104B92DD56}')
        coclass_clsid = IID('{FC1820B7-691D-11D4-8457-00104B92DD56}')

        def Abort(self):
                return self._oleobj_.InvokeTypes(8, LCID, 1, (11, 0), (),)

        def CloseDocument(self, bstrPath=defaultNamedNotOptArg, lState=0):
                return self._oleobj_.InvokeTypes(6, LCID, 1, (3, 0), ((8, 1), 
(3, 49)),bstrPath
                        , lState)

        def ExecuteDocument(self, bstrPath=defaultNamedNotOptArg, lState=0):
                return self._oleobj_.InvokeTypes(7, LCID, 1, (3, 0), ((8, 1), 
(3, 49)),bstrPath
                        , lState)

        def OpenDocument(self, bstrPath=defaultNamedNotOptArg, lState=1):
                return self._oleobj_.InvokeTypes(5, LCID, 1, (3, 0), ((8, 1), 
(3, 49)),bstrPath
                        , lState)

        _prop_map_get_ = {
                "Config": (2, 2, (8, 0), (), "Config", None),
                "ConfigFile": (1, 2, (8, 0), (), "ConfigFile", None),
                "Visible": (3, 2, (11, 0), (), "Visible", None),
                "ProcessID": (4, 2, (8, 0), (), "ProcessID", None),
        }
        _prop_map_put_ = {
                "Config" : ((2, LCID, 4, 0),()),
                "ConfigFile" : ((1, LCID, 4, 0),()),
                "Visible" : ((3, LCID, 4, 0),()),
        }

class IApplicationEvents:
        """IApplicationEvents Interface"""
        CLSID = CLSID_Sink = IID('{93FF3980-6D2A-11D4-8459-00104B92DD56}')
        coclass_clsid = IID('{FC1820B7-691D-11D4-8457-00104B92DD56}')
        _public_methods_ = [] # For COM Server support
        _dispid_to_func_ = {
                1610678275 : "OnInvoke",
                        2 : "OnError",
                        1 : "OnState",
                1610678273 : "OnGetTypeInfo",
                1610612737 : "OnAddRef",
                1610612736 : "OnQueryInterface",
                1610612738 : "OnRelease",
                        3 : "OnMessage",
                1610678274 : "OnGetIDsOfNames",
                1610678272 : "OnGetTypeInfoCount",
                }

        def __init__(self, oobj = None):
                if oobj is None:
                        self._olecp = None
                else:
                        import win32com.server.util
                        from win32com.server.policy import EventHandlerPolicy
                        
cpc=oobj._oleobj_.QueryInterface(pythoncom.IID_IConnectionPointContainer)
                        cp=cpc.FindConnectionPoint(self.CLSID_Sink)
                        cookie=cp.Advise(win32com.server.util.wrap(self, 
usePolicy=EventHandlerPolicy))
                        self._olecp,self._olecp_cookie = cp,cookie
        def __del__(self):
                try:
                        self.close()
                except pythoncom.com_error:
                        pass
        def close(self):
                if self._olecp is not None:
                        cp,cookie,self._olecp,self._olecp_cookie = 
self._olecp,self._olecp_cookie,None,None
                        cp.Unadvise(cookie)
        def _query_interface_(self, iid):
                import win32com.server.util
                if iid==self.CLSID_Sink: return win32com.server.util.wrap(self)

        # Event Handlers
        # If you create handlers, they should have the following prototypes:
#       def OnInvoke(self, dispidMember=defaultNamedNotOptArg, 
riid=defaultNamedNotOptArg, lcid=defaultNamedNotOptArg, 
wFlags=defaultNamedNotOptArg
#                       , pdispparams=defaultNamedNotOptArg, 
pvarResult=pythoncom.Missing, pexcepinfo=pythoncom.Missing, 
puArgErr=pythoncom.Missing):
#       def OnError(self, ErrorID=defaultNamedNotOptArg, 
ErrorMsg=defaultNamedNotOptArg, HelpContext=defaultNamedNotOptArg, 
HelpFile=defaultNamedNotOptArg):
#       def OnState(self, Status=defaultNamedNotOptArg):
#       def OnGetTypeInfo(self, itinfo=defaultNamedNotOptArg, 
lcid=defaultNamedNotOptArg, pptinfo=pythoncom.Missing):
#       def OnAddRef(self):
#       def OnQueryInterface(self, riid=defaultNamedNotOptArg, 
ppvObj=pythoncom.Missing):
#       def OnRelease(self):
#       def OnMessage(self, Text=defaultNamedNotOptArg, 
Flags=defaultNamedNotOptArg):
#       def OnGetIDsOfNames(self, riid=defaultNamedNotOptArg, 
rgszNames=defaultNamedNotOptArg, cNames=defaultNamedNotOptArg, 
lcid=defaultNamedNotOptArg
#                       , rgdispid=pythoncom.Missing):
#       def OnGetTypeInfoCount(self, pctinfo=pythoncom.Missing):


class IDocumentEvents:
        """IDocumentEvents Interface"""
        CLSID = CLSID_Sink = IID('{93FF3981-6D2A-11D4-8459-00104B92DD56}')
        coclass_clsid = IID('{FC1820B7-691D-11D4-8457-00104B92DD56}')
        _public_methods_ = [] # For COM Server support
        _dispid_to_func_ = {
                1610678275 : "OnInvoke",
                        1 : "OnCommand",
                1610678273 : "OnGetTypeInfo",
                1610612737 : "OnAddRef",
                1610612736 : "OnQueryInterface",
                1610612738 : "OnRelease",
                1610678274 : "OnGetIDsOfNames",
                1610678272 : "OnGetTypeInfoCount",
                }

        def __init__(self, oobj = None):
                if oobj is None:
                        self._olecp = None
                else:
                        import win32com.server.util
                        from win32com.server.policy import EventHandlerPolicy
                        
cpc=oobj._oleobj_.QueryInterface(pythoncom.IID_IConnectionPointContainer)
                        cp=cpc.FindConnectionPoint(self.CLSID_Sink)
                        cookie=cp.Advise(win32com.server.util.wrap(self, 
usePolicy=EventHandlerPolicy))
                        self._olecp,self._olecp_cookie = cp,cookie
        def __del__(self):
                try:
                        self.close()
                except pythoncom.com_error:
                        pass
        def close(self):
                if self._olecp is not None:
                        cp,cookie,self._olecp,self._olecp_cookie = 
self._olecp,self._olecp_cookie,None,None
                        cp.Unadvise(cookie)
        def _query_interface_(self, iid):
                import win32com.server.util
                if iid==self.CLSID_Sink: return win32com.server.util.wrap(self)

        # Event Handlers
        # If you create handlers, they should have the following prototypes:
#       def OnInvoke(self, dispidMember=defaultNamedNotOptArg, 
riid=defaultNamedNotOptArg, lcid=defaultNamedNotOptArg, 
wFlags=defaultNamedNotOptArg
#                       , pdispparams=defaultNamedNotOptArg, 
pvarResult=pythoncom.Missing, pexcepinfo=pythoncom.Missing, 
puArgErr=pythoncom.Missing):
#       def OnCommand(self, Titel=defaultNamedNotOptArg, 
Parameter=defaultNamedNotOptArg):
#       def OnGetTypeInfo(self, itinfo=defaultNamedNotOptArg, 
lcid=defaultNamedNotOptArg, pptinfo=pythoncom.Missing):
#       def OnAddRef(self):
#       def OnQueryInterface(self, riid=defaultNamedNotOptArg, 
ppvObj=pythoncom.Missing):
#       def OnRelease(self):
#       def OnGetIDsOfNames(self, riid=defaultNamedNotOptArg, 
rgszNames=defaultNamedNotOptArg, cNames=defaultNamedNotOptArg, 
lcid=defaultNamedNotOptArg
#                       , rgdispid=pythoncom.Missing):
#       def OnGetTypeInfoCount(self, pctinfo=pythoncom.Missing):


from win32com.client import CoClassBaseClass
# This CoClass is known by the name 'OpalControl.Application'
class Application(CoClassBaseClass): # A CoClass
        CLSID = IID('{FC1820B7-691D-11D4-8457-00104B92DD56}')
        coclass_sources = [
                IApplicationEvents,
                IDocumentEvents,
        ]
        default_source = IApplicationEvents
        coclass_interfaces = [
                IApplication,
        ]
        default_interface = IApplication

IApplicationEvents_vtables_dispatch_ = 1
IApplicationEvents_vtables_ = [
        (( 'OnState' , 'Status' , ), 1, (1, (), [ (3, 1, None, None) , ], 1 , 1 
, 4 , 0 , 28 , (3, 0, None, None) , 0 , )),
        (( 'OnError' , 'ErrorID' , 'ErrorMsg' , 'HelpContext' , 'HelpFile' , 
                        ), 2, (2, (), [ (3, 1, None, None) , (8, 1, None, None) 
, (3, 1, None, None) , (8, 1, None, None) , ], 1 , 1 , 4 , 0 , 32 , (3, 0, 
None, None) , 0 , )),
        (( 'OnMessage' , 'Text' , 'Flags' , 'plRetval' , ), 3, (3, (), [ 
                        (8, 1, None, None) , (3, 1, None, None) , (16387, 10, 
None, None) , ], 1 , 1 , 4 , 0 , 36 , (3, 0, None, None) , 0 , )),
]

IDocumentEvents_vtables_dispatch_ = 1
IDocumentEvents_vtables_ = [
        (( 'OnCommand' , 'Titel' , 'Parameter' , ), 1, (1, (), [ (8, 1, None, 
None) , 
                        (8, 1, None, None) , ], 1 , 1 , 4 , 0 , 28 , (3, 0, 
None, None) , 0 , )),
]

RecordMap = {
}

CLSIDToClassMap = {
        '{93FF3980-6D2A-11D4-8459-00104B92DD56}' : IApplicationEvents,
        '{FC1820B6-691D-11D4-8457-00104B92DD56}' : IApplication,
        '{FC1820B7-691D-11D4-8457-00104B92DD56}' : Application,
        '{93FF3981-6D2A-11D4-8459-00104B92DD56}' : IDocumentEvents,
}
CLSIDToPackageMap = {}
win32com.client.CLSIDToClass.RegisterCLSIDsFromDict( CLSIDToClassMap )
VTablesToPackageMap = {}
VTablesToClassMap = {
        '{93FF3980-6D2A-11D4-8459-00104B92DD56}' : 'IApplicationEvents',
        '{93FF3981-6D2A-11D4-8459-00104B92DD56}' : 'IDocumentEvents',
}


NamesToIIDMap = {
        'IApplicationEvents' : '{93FF3980-6D2A-11D4-8459-00104B92DD56}',
        'IApplication' : '{FC1820B6-691D-11D4-8457-00104B92DD56}',
        'IDocumentEvents' : '{93FF3981-6D2A-11D4-8459-00104B92DD56}',
}


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

Reply via email to