S
seacuke
I am not even sure how to search for instances of this issue, so please
forgive me if this is a duplicate.
I have two seperate programs that are playing with Outlook. One is a
view control that's wrapped in a .net user control that is hit via a
web site. The other is an add-in that adds a button to Outlook and
does some processing with it.
Both seem to work fine... if Outlook is started before the view control
page is hit. However, if Outlook is not started, and the Add-in *is*
loaded into Outlook, and the user hits the view control, there are
exceptions thrown. No real indication of what kind of exception is
thrown, basically the user control doesn't load.
I am suspicious of my add-in's logic for attaching its button to the
command bar; but does anyone know a good, reliable way to determine if
a command bar is present, and if not, *unload* the add-in?
This is to support OLK2000 and later, and as I mentioned, everything
functions fine if Outlook is started before the view control is loaded;
but there is no guarantee that Outlook *will* be started before the
view control is loaded.
Here's part of my add-in code (maybe cut/paste to get the formatting
better?):
public void OnConnection(object application,
Extensibility.ext_ConnectMode connectMode, object addInInst, ref
System.Array custom)
{
try
{
if (application is Outlook.Application)
{
applicationObject = (Outlook.Application)application;
addInInstance = addInInst;
versionNumber =
int.Parse(applicationObject.Version.Substring(0,applicationObject.Version.IndexOf('.')));
if (versionNumber < 9)
{
MessageBox.Show("Only Outlook versions 2000 and later
are supported at this time.",
"Incompatible Outlook Version");
}
this.sessionId = "";
}
else
{
applicationObject = null;
addInInstance = null;
}
}
catch (System.Exception e)
{
MessageBox.Show(e.ToString(),"OnConnection");
}
}
public void OnStartupComplete(ref System.Array custom)
{
if (applicationObject == null)
{
return;
}
if (addInInstance == null)
{
return;
}
if (versionNumber < 9)
{
return;
}
Office.CommandBars commandBars;
try
{
activeMailItems = new Hashtable(25);
sentMailItems = new ArrayList(25);
// Need to add an event handler for when
//the 'sent items' folder gets a new
// email applied to it.
sentItems = applicationObject.GetNamespace
("MAPI").GetDefaultFolder
(Outlook.OlDefaultFolders.olFolderSentMail).Items;
sentItems.ItemAdd +=new
Outlook.ItemsEvents_ItemAddEventHandler(sentItems_ItemAdd);
activeExplorer.SelectionChange += new
Outlook.ExplorerEvents_SelectionChangeEventHandler(activeExplorer_SelectionChange);
activeExplorer.FolderSwitch += new
Outlook.ExplorerEvents_FolderSwitchEventHandler(activeExplorer_FolderSwitch);
inspectorsClass =
(Outlook.InspectorsClass)applicationObject.Inspectors;
if (inspectorsClass != null)
{
inspectorsClass.NewInspector +=new
Outlook.InspectorsEvents_NewInspectorEventHandler(inspectorsClass_NewInspector);
}
activeExplorer =
(Outlook.Explorer)applicationObject.ActiveExplorer();
if (activeExplorer != null)
{
new
RNTOutlookSync.outlookExplorerCloseEvent(activeExplorer,new
RNTOutlookSync.outlookExplorerCloseEvent.Handler(this.explorerClose));
commandBars = activeExplorer.CommandBars;
if (commandBars != null)
{
syncButton =
(Office.CommandBarButton)commandBars["Standard"].FindControl(Office.MsoControlType.msoControlButton,
System.Reflection.Missing.Value,
"MainSync",
System.Reflection.Missing.Value,
false);
...
}
}
}
catch (System.Exception e)
{
MessageBox.Show(e.ToString(),"On Startup Complete");
}
}
forgive me if this is a duplicate.
I have two seperate programs that are playing with Outlook. One is a
view control that's wrapped in a .net user control that is hit via a
web site. The other is an add-in that adds a button to Outlook and
does some processing with it.
Both seem to work fine... if Outlook is started before the view control
page is hit. However, if Outlook is not started, and the Add-in *is*
loaded into Outlook, and the user hits the view control, there are
exceptions thrown. No real indication of what kind of exception is
thrown, basically the user control doesn't load.
I am suspicious of my add-in's logic for attaching its button to the
command bar; but does anyone know a good, reliable way to determine if
a command bar is present, and if not, *unload* the add-in?
This is to support OLK2000 and later, and as I mentioned, everything
functions fine if Outlook is started before the view control is loaded;
but there is no guarantee that Outlook *will* be started before the
view control is loaded.
Here's part of my add-in code (maybe cut/paste to get the formatting
better?):
public void OnConnection(object application,
Extensibility.ext_ConnectMode connectMode, object addInInst, ref
System.Array custom)
{
try
{
if (application is Outlook.Application)
{
applicationObject = (Outlook.Application)application;
addInInstance = addInInst;
versionNumber =
int.Parse(applicationObject.Version.Substring(0,applicationObject.Version.IndexOf('.')));
if (versionNumber < 9)
{
MessageBox.Show("Only Outlook versions 2000 and later
are supported at this time.",
"Incompatible Outlook Version");
}
this.sessionId = "";
}
else
{
applicationObject = null;
addInInstance = null;
}
}
catch (System.Exception e)
{
MessageBox.Show(e.ToString(),"OnConnection");
}
}
public void OnStartupComplete(ref System.Array custom)
{
if (applicationObject == null)
{
return;
}
if (addInInstance == null)
{
return;
}
if (versionNumber < 9)
{
return;
}
Office.CommandBars commandBars;
try
{
activeMailItems = new Hashtable(25);
sentMailItems = new ArrayList(25);
// Need to add an event handler for when
//the 'sent items' folder gets a new
// email applied to it.
sentItems = applicationObject.GetNamespace
("MAPI").GetDefaultFolder
(Outlook.OlDefaultFolders.olFolderSentMail).Items;
sentItems.ItemAdd +=new
Outlook.ItemsEvents_ItemAddEventHandler(sentItems_ItemAdd);
activeExplorer.SelectionChange += new
Outlook.ExplorerEvents_SelectionChangeEventHandler(activeExplorer_SelectionChange);
activeExplorer.FolderSwitch += new
Outlook.ExplorerEvents_FolderSwitchEventHandler(activeExplorer_FolderSwitch);
inspectorsClass =
(Outlook.InspectorsClass)applicationObject.Inspectors;
if (inspectorsClass != null)
{
inspectorsClass.NewInspector +=new
Outlook.InspectorsEvents_NewInspectorEventHandler(inspectorsClass_NewInspector);
}
activeExplorer =
(Outlook.Explorer)applicationObject.ActiveExplorer();
if (activeExplorer != null)
{
new
RNTOutlookSync.outlookExplorerCloseEvent(activeExplorer,new
RNTOutlookSync.outlookExplorerCloseEvent.Handler(this.explorerClose));
commandBars = activeExplorer.CommandBars;
if (commandBars != null)
{
syncButton =
(Office.CommandBarButton)commandBars["Standard"].FindControl(Office.MsoControlType.msoControlButton,
System.Reflection.Missing.Value,
"MainSync",
System.Reflection.Missing.Value,
false);
...
}
}
}
catch (System.Exception e)
{
MessageBox.Show(e.ToString(),"On Startup Complete");
}
}