[pywin32-bugs] PyWin32 Outlook Adding crashes Outlook on Window 2003 SP1
OLD project page for the Python extensions for Windows
Brought to you by:
mhammond
|
From: Sean C. <sea...@co...> - 2005-05-15 11:34:01
|
To all,
I've been using SpamBayes for some time on Window 2003 Server. After
upgrading to Windows 2003, the plugin no longer works. After some
debugging, It was determined it was probably a PyWin32 problem.
Python 2.4.1
pywin32-204.win32-py2.4.exe
I have tested the example Outlook plugin
(win32com/demos/Outlookadin.py). That plugin also crashes Outlook. I
added a bunch of win32traceutil;print statements to attempt to figure
out where the crash it.
The output I get is this:
Collecting Python Trace Output...
Starting up 1
Starting up 2
Starting up 3
Starting up 6
Starting up 7
Here's the code:
-------------------------------------------------
from win32com import universal
from win32com.server.exception import COMException
from win32com.client import gencache, DispatchWithEvents
import winerror
import pythoncom
from win32com.client import constants
import sys
import win32traceutil
win32traceutil;print 'Starting up 1'
# Support for COM objects we use.
gencache.EnsureModule('{00062FFF-0000-0000-C000-000000000046}', 0, 9, 0,
bForDemand=True) # Outlook 9
gencache.EnsureModule('{2DF8D04C-5BFA-101B-BDE5-00AA0044DE52}', 0, 2, 1,
bForDemand=True) # Office 9
win32traceutil;print 'Starting up 2'
# The TLB defiining the interfaces we implement
universal.RegisterInterfaces('{AC0714F2-3D04-11D1-AE7D-00A0C90F26F4}',
0, 1, 0, ["_IDTExtensibility2"])
win32traceutil;print 'Starting up 3'
class ButtonEvent:
def OnClick(self, button, cancel):
win32traceutil;print 'Starting up 4'
import win32ui # Possible, but not necessary, to use a Pythonwin GUI
win32ui.MessageBox("Hello from Python")
return cancel
class FolderEvent:
def OnItemAdd(self, item):
win32traceutil;print 'Starting up 5'
try:
print "An item was added to the inbox with subject:",
item.Subject
except AttributeError:
print "An item was added to the inbox, but it has no
subject! - ", repr(item)
class OutlookAddin:
win32traceutil;print 'Starting up 6'
_com_interfaces_ = ['_IDTExtensibility2']
_public_methods_ = []
_reg_clsctx_ = pythoncom.CLSCTX_INPROC_SERVER
_reg_clsid_ = "{0F47D9F3-598B-4d24-B7E3-92AC15ED27E2}"
_reg_progid_ = "Python.Test.OutlookAddin"
_reg_policy_spec_ = "win32com.server.policy.EventHandlerPolicy"
win32traceutil;print 'Starting up 7'
def OnConnection(self, application, connectMode, addin, custom):
win32traceutil;print 'OnConnection'
print "OnConnection", application, connectMode, addin, custom
# ActiveExplorer may be none when started without a UI (eg,
WinCE synchronisation)
activeExplorer = application.ActiveExplorer()
if activeExplorer is not None:
bars = activeExplorer.CommandBars
toolbar = bars.Item("Standard")
item = toolbar.Controls.Add(Type=constants.msoControlButton,
Temporary=True)
# Hook events for the item
item = self.toolbarButton = DispatchWithEvents(item,
ButtonEvent)
item.Caption="Python"
item.TooltipText = "Click for Python"
item.Enabled = True
win32traceutil;print 'Setup Hooks'
# And now, for the sake of demonstration, setup a hook for all
new messages
inbox =
application.Session.GetDefaultFolder(constants.olFolderInbox)
self.inboxItems = DispatchWithEvents(inbox.Items, FolderEvent)
def OnDisconnection(self, mode, custom):
win32traceutil;print 'Starting up 8'
print "OnDisconnection"
def OnAddInsUpdate(self, custom):
win32traceutil;print 'Starting up 9'
print "OnAddInsUpdate", custom
def OnStartupComplete(self, custom):
win32traceutil;print 'Starting up 10'
print "OnStartupComplete", custom
def OnBeginShutdown(self, custom):
win32traceutil;print 'Starting up 11'
print "OnBeginShutdown", custom
def RegisterAddin(klass):
win32traceutil;print 'RegisterAddin'
import _winreg
key = _winreg.CreateKey(_winreg.HKEY_CURRENT_USER,
"Software\\Microsoft\\Office\\Outlook\\Addins")
subkey = _winreg.CreateKey(key, klass._reg_progid_)
_winreg.SetValueEx(subkey, "CommandLineSafe", 0, _winreg.REG_DWORD, 0)
_winreg.SetValueEx(subkey, "LoadBehavior", 0, _winreg.REG_DWORD, 3)
_winreg.SetValueEx(subkey, "Description", 0, _winreg.REG_SZ,
klass._reg_progid_)
_winreg.SetValueEx(subkey, "FriendlyName", 0, _winreg.REG_SZ,
klass._reg_progid_)
def UnregisterAddin(klass):
win32traceutil;print 'UnregesterAddin'
import _winreg
try:
_winreg.DeleteKey(_winreg.HKEY_CURRENT_USER,
"Software\\Microsoft\\Office\\Outlook\\Addins\\" + klass._reg_progid_)
except WindowsError:
pass
if __name__ == '__main__':
import win32com.server.register
win32com.server.register.UseCommandLine(OutlookAddin)
if "--unregister" in sys.argv:
UnregisterAddin(OutlookAddin)
else:
RegisterAddin(OutlookAddin)
---------------------------------------------------------------
Anything I can do to help, just let me know.
Sean
|