I am writing a COM addin, and attempting to trap the ItemAdded/ItemRemoved event in the following object: Application.VBE.Events.ReferencesEvents which is retrieved by passing Nothing as a paramter: Application.VBE.Events.ReferencesEvents(Nothing)
Tim Golden wrote in the following post (http://mail.python.org/pipermail/python-win32/2009-February/008826.html) that pythoncom.Empty can be used for Nothing. However, when trying this: try: self.comRefevents=self.app.VBE.Events.ReferencesEvents(pythoncom.Empty) except pythoncom.com_error, (hr, msg, exc, arg): print "The call failed with code %d: %s" % (hr, msg) if exc is None: print "There is no extended error information" else: wcode, source, text, helpFile, helpId, scode = exc print "The source of the error is", source print "The error message is", text print "More info can be found in %s (id=%d)" % (helpFile, helpId) I get back the following (the same as if I had passed no arguments at all): The call failed with code -2147352561: Parameter not optional. There is no extended error information Eric Lippert states in his blog (http://blogs.msdn.com/ericlippert/archive/2004/07/14/183241.aspx): > A common alternative to passing a missing argument is to pass Nothing, Null, > or Empty in VBScript, > null or undefined in JScript. Null and null pass VT_NULL, Empty and > undefined pass VT_EMPTY, and > Nothing passes a VT_DISPATCH with no value dispatch object pointer. It would seem that VB's Nothing and Empty are two different things. If I try passing pythoncom.VT_DISPATCH, then I get the following traceback: ----------------------------------------------------------------------------------------------------------- Traceback (most recent call last): File "C:\Python26\lib\site-packages\win32com\universal.py", line 177, in dispatch retVal = ob._InvokeEx_(meth.dispid, 0, meth.invkind, args, None, None) File "C:\Python26\lib\site-packages\win32com\server\policy.py", line 324, in _InvokeEx_ return self._invokeex_(dispid, lcid, wFlags, args, kwargs, serviceProvider) File "C:\Python26\lib\site-packages\win32com\server\policy.py", line 649, in _invokeex_ return DesignatedWrapPolicy._invokeex_( self, dispid, lcid, wFlags, args, kwArgs, serviceProvider) File "C:\Python26\lib\site-packages\win32com\server\policy.py", line 585, in _invokeex_ return func(*args) File "C:\Documents and Settings\ABG7\My Documents\Zevi\Python-COMAddin\VBACodeRepository.py", line 104, in OnConnection self.comRefevents=self.app.VBE.Events.ReferencesEvents(pythoncom.VT_DISPATCH) File "C:\Python26\lib\site-packages\win32com\gen_py\0002E157-0000-0000-C000-000000000046x0x5x3.py", line 145, in ReferencesEvents ret = self._oleobj_.InvokeTypes(202, LCID, 2, (13, 0), ((13, 1),),VBProject TypeError: The Python instance can not be converted to a COM object pythoncom error: Unexpected gateway error Traceback (most recent call last): File "C:\Python26\lib\site-packages\win32com\universal.py", line 177, in dispatch retVal = ob._InvokeEx_(meth.dispid, 0, meth.invkind, args, None, None) File "C:\Python26\lib\site-packages\win32com\server\policy.py", line 324, in _InvokeEx_ return self._invokeex_(dispid, lcid, wFlags, args, kwargs, serviceProvider) File "C:\Python26\lib\site-packages\win32com\server\policy.py", line 649, in _invokeex_ return DesignatedWrapPolicy._invokeex_( self, dispid, lcid, wFlags, args, kwArgs, serviceProvider) File "C:\Python26\lib\site-packages\win32com\server\policy.py", line 585, in _invokeex_ return func(*args) File "C:\Documents and Settings\ABG7\My Documents\Python-COMAddin\VBACodeRepository.py", line 104, in OnConnection self.comRefevents=self.app.VBE.Events.ReferencesEvents(pythoncom.VT_DISPATCH) File "C:\Python26\lib\site-packages\win32com\gen_py\0002E157-0000-0000-C000-000000000046x0x5x3.py", line 145, in ReferencesEvents ret = self._oleobj_.InvokeTypes(202, LCID, 2, (13, 0), ((13, 1),),VBProject TypeError: The Python instance can not be converted to a COM object -----------------------------------------------------------------------------------------------------------
_______________________________________________ python-win32 mailing list python-win32@python.org http://mail.python.org/mailman/listinfo/python-win32