SUPER NEWB: 2 simple questions

S

sklett

- Visual Studio 2005
- C#
- Outlook 2003 (standalone)

I've been reading about managed COM add-ins for 2 days and I finally decided
to get my hands dirty and write some code.
I follwed the example in this article:
http://msdn2.microsoft.com/en-us/library/aa289167(vs.71).aspx

Which I felt was very clear and explained things well.

My 2 problems I'm having are:
1) After running my installer (auto generated by the VS2k5 template) and
launching a debug session from VS2k5 my add-in is not listed in the COM
add-ins list, however the add-in is working. I can step through my code and
the simple CommandBarButton that I'm adding shows up in the UI. So why
would my add-in not be listed if it is indeeded loaded and working?

2) In the OnBeginShutdown event I was catching "object reference not set to
an instance of an object" after doing some googling I tried checking the
Count property of Application.Explorers and it was 0! How can I clean up my
UI if everyone has left the building?

So that's it, I'm off to a rough start.

I'll paste my code here with hopes it will shed some light.
<code>
[GuidAttribute("0FF6BFF0-6898-4C5B-9943-1DB6B9A7C898"),
ProgId("MyAddin1.Connect")]
public class Connect : Object, Extensibility.IDTExtensibility2
{
private Microsoft.Office.Interop.Outlook.Application _applicationObject;
private object addInInstance;

// UI
private CommandBarButton _buttonTest = null;

public Connect()
{

}

public void OnConnection(object application, Extensibility.ext_ConnectMode
connectMode, object addInInst, ref System.Array custom)
{
_applicationObject =
(Microsoft.Office.Interop.Outlook.Application)application;
addInInstance = addInInst;
if (connectMode != ext_ConnectMode.ext_cm_Startup)
{
OnStartupComplete(ref custom);
}
}


public void OnDisconnection(Extensibility.ext_DisconnectMode
disconnectMode, ref System.Array custom)
{
if (disconnectMode != ext_DisconnectMode.ext_dm_HostShutdown)
{
OnBeginShutdown(ref custom);
}
_applicationObject = null;
}

public void OnAddInsUpdate(ref System.Array custom)
{

}

public void OnStartupComplete(ref System.Array custom)
{
CommandBars commandBars =
_applicationObject.ActiveExplorer().CommandBars;

try
{
CommandBarButton _buttonTest =
(CommandBarButton)commandBars["Standard"].Controls["SK Test"];
}
catch
{
_buttonTest =
(CommandBarButton)commandBars["Standard"].Controls.Add(
1,
Missing.Value,
Missing.Value,
Missing.Value,
Missing.Value);

_buttonTest.Caption = "SK Test";
_buttonTest.Style = MsoButtonStyle.msoButtonCaption;
_buttonTest.Tag = "SK Test";
_buttonTest.OnAction = "!<MyAddin1.Connect>";
_buttonTest.Visible = true;

_buttonTest.Click += new
_CommandBarButtonEvents_ClickEventHandler(_buttonTest_Click);
}
}

void _buttonTest_Click(CommandBarButton Ctrl, ref bool CancelDefault)
{
StoreScriptRequest dlg = new StoreScriptRequest();
dlg.ShowDialog();
}


public void OnBeginShutdown(ref System.Array custom)
{
try
{
if (_applicationObject.Explorers.Count > 0)
{
CommandBars commandBars =
_applicationObject.ActiveExplorer().CommandBars;
commandBars["Standard"].Controls["SK
Test"].Delete(Missing.Value);
}
}
catch(System.Exception e)
{
MessageBox.Show(e.Message);
}
}
}
</code>


I'm hoping there is a logical explanation for what I'm experiencing. If
anyone has any ideas or suggestions, I would REALLY appreciate it.

Thanks for reading,
Steve
 
A

Andrei Smolin

Steve,

Please check out Add-in Express (http://www.add-in-express.com/add-in-net/).
It provides components for creating COM add-ins: command bars and controls,
Ribbon UI components, Outlook property pages, Outlook Bar (Navigation pane)
shortcuts etc. And the most striking feature - embedding custom .NET forms
into Outlook windows (http://www.add-in-express.com/outlook-extension/).

Now, to your questions.

1. The COM Add-ns dialog doesn't show add-ins registered in HKLM.
2. In Outlook, you should add custom command bar controls as Temporary. To
delete the control, just use the _buttonTest variable.

You can face a lot more problems already solved in Add-in Express (say, you
can find that your variable sometimes "lose" the control and fires
exceptions). And our Support Team guys will help you to break through the
difficulties: we include support into Add-in Express product packages.

Regards from Belarus,

Andrei Smolin
Add-in Express Team Leader

sklett said:
- Visual Studio 2005
- C#
- Outlook 2003 (standalone)

I've been reading about managed COM add-ins for 2 days and I finally
decided to get my hands dirty and write some code.
I follwed the example in this article:
http://msdn2.microsoft.com/en-us/library/aa289167(vs.71).aspx

Which I felt was very clear and explained things well.

My 2 problems I'm having are:
1) After running my installer (auto generated by the VS2k5 template) and
launching a debug session from VS2k5 my add-in is not listed in the COM
add-ins list, however the add-in is working. I can step through my code
and the simple CommandBarButton that I'm adding shows up in the UI. So
why would my add-in not be listed if it is indeeded loaded and working?

2) In the OnBeginShutdown event I was catching "object reference not set
to an instance of an object" after doing some googling I tried checking
the Count property of Application.Explorers and it was 0! How can I clean
up my UI if everyone has left the building?

So that's it, I'm off to a rough start.

I'll paste my code here with hopes it will shed some light.
<code>
[GuidAttribute("0FF6BFF0-6898-4C5B-9943-1DB6B9A7C898"),
ProgId("MyAddin1.Connect")]
public class Connect : Object, Extensibility.IDTExtensibility2
{
private Microsoft.Office.Interop.Outlook.Application
_applicationObject;
private object addInInstance;

// UI
private CommandBarButton _buttonTest = null;

public Connect()
{

}

public void OnConnection(object application, Extensibility.ext_ConnectMode
connectMode, object addInInst, ref System.Array custom)
{
_applicationObject =
(Microsoft.Office.Interop.Outlook.Application)application;
addInInstance = addInInst;
if (connectMode != ext_ConnectMode.ext_cm_Startup)
{
OnStartupComplete(ref custom);
}
}


public void OnDisconnection(Extensibility.ext_DisconnectMode
disconnectMode, ref System.Array custom)
{
if (disconnectMode != ext_DisconnectMode.ext_dm_HostShutdown)
{
OnBeginShutdown(ref custom);
}
_applicationObject = null;
}

public void OnAddInsUpdate(ref System.Array custom)
{

}

public void OnStartupComplete(ref System.Array custom)
{
CommandBars commandBars =
_applicationObject.ActiveExplorer().CommandBars;

try
{
CommandBarButton _buttonTest =
(CommandBarButton)commandBars["Standard"].Controls["SK Test"];
}
catch
{
_buttonTest =
(CommandBarButton)commandBars["Standard"].Controls.Add(
1,
Missing.Value,
Missing.Value,
Missing.Value,
Missing.Value);

_buttonTest.Caption = "SK Test";
_buttonTest.Style = MsoButtonStyle.msoButtonCaption;
_buttonTest.Tag = "SK Test";
_buttonTest.OnAction = "!<MyAddin1.Connect>";
_buttonTest.Visible = true;

_buttonTest.Click += new
_CommandBarButtonEvents_ClickEventHandler(_buttonTest_Click);
}
}

void _buttonTest_Click(CommandBarButton Ctrl, ref bool CancelDefault)
{
StoreScriptRequest dlg = new StoreScriptRequest();
dlg.ShowDialog();
}


public void OnBeginShutdown(ref System.Array custom)
{
try
{
if (_applicationObject.Explorers.Count > 0)
{
CommandBars commandBars =
_applicationObject.ActiveExplorer().CommandBars;
commandBars["Standard"].Controls["SK
Test"].Delete(Missing.Value);
}
}
catch(System.Exception e)
{
MessageBox.Show(e.Message);
}
}
}
</code>


I'm hoping there is a logical explanation for what I'm experiencing. If
anyone has any ideas or suggestions, I would REALLY appreciate it.

Thanks for reading,
Steve
 
K

Ken Slovak - [MVP - Outlook]

Is your addin set for installing for [all users] and not for [current user]?
An all users installation gets registered in
HKLM\Software\Microsoft\Office\Outlook\Addins. A current user installation
gets registered in the equivalent key in HKCU.

Addins registered in HKLM do not show up in the COM Add-Ins dialog, they are
administrative installations. Check the registry when your addin is running.

Trap Explorer.Close() and release your Explorer UI there.




sklett said:
- Visual Studio 2005
- C#
- Outlook 2003 (standalone)

I've been reading about managed COM add-ins for 2 days and I finally
decided to get my hands dirty and write some code.
I follwed the example in this article:
http://msdn2.microsoft.com/en-us/library/aa289167(vs.71).aspx

Which I felt was very clear and explained things well.

My 2 problems I'm having are:
1) After running my installer (auto generated by the VS2k5 template) and
launching a debug session from VS2k5 my add-in is not listed in the COM
add-ins list, however the add-in is working. I can step through my code
and the simple CommandBarButton that I'm adding shows up in the UI. So
why would my add-in not be listed if it is indeeded loaded and working?

2) In the OnBeginShutdown event I was catching "object reference not set
to an instance of an object" after doing some googling I tried checking
the Count property of Application.Explorers and it was 0! How can I clean
up my UI if everyone has left the building?

So that's it, I'm off to a rough start.

I'll paste my code here with hopes it will shed some light.
<code>
[GuidAttribute("0FF6BFF0-6898-4C5B-9943-1DB6B9A7C898"),
ProgId("MyAddin1.Connect")]
public class Connect : Object, Extensibility.IDTExtensibility2
{
private Microsoft.Office.Interop.Outlook.Application
_applicationObject;
private object addInInstance;

// UI
private CommandBarButton _buttonTest = null;

public Connect()
{

}

public void OnConnection(object application, Extensibility.ext_ConnectMode
connectMode, object addInInst, ref System.Array custom)
{
_applicationObject =
(Microsoft.Office.Interop.Outlook.Application)application;
addInInstance = addInInst;
if (connectMode != ext_ConnectMode.ext_cm_Startup)
{
OnStartupComplete(ref custom);
}
}


public void OnDisconnection(Extensibility.ext_DisconnectMode
disconnectMode, ref System.Array custom)
{
if (disconnectMode != ext_DisconnectMode.ext_dm_HostShutdown)
{
OnBeginShutdown(ref custom);
}
_applicationObject = null;
}

public void OnAddInsUpdate(ref System.Array custom)
{

}

public void OnStartupComplete(ref System.Array custom)
{
CommandBars commandBars =
_applicationObject.ActiveExplorer().CommandBars;

try
{
CommandBarButton _buttonTest =
(CommandBarButton)commandBars["Standard"].Controls["SK Test"];
}
catch
{
_buttonTest =
(CommandBarButton)commandBars["Standard"].Controls.Add(
1,
Missing.Value,
Missing.Value,
Missing.Value,
Missing.Value);

_buttonTest.Caption = "SK Test";
_buttonTest.Style = MsoButtonStyle.msoButtonCaption;
_buttonTest.Tag = "SK Test";
_buttonTest.OnAction = "!<MyAddin1.Connect>";
_buttonTest.Visible = true;

_buttonTest.Click += new
_CommandBarButtonEvents_ClickEventHandler(_buttonTest_Click);
}
}

void _buttonTest_Click(CommandBarButton Ctrl, ref bool CancelDefault)
{
StoreScriptRequest dlg = new StoreScriptRequest();
dlg.ShowDialog();
}


public void OnBeginShutdown(ref System.Array custom)
{
try
{
if (_applicationObject.Explorers.Count > 0)
{
CommandBars commandBars =
_applicationObject.ActiveExplorer().CommandBars;
commandBars["Standard"].Controls["SK
Test"].Delete(Missing.Value);
}
}
catch(System.Exception e)
{
MessageBox.Show(e.Message);
}
}
}
</code>


I'm hoping there is a logical explanation for what I'm experiencing. If
anyone has any ideas or suggestions, I would REALLY appreciate it.

Thanks for reading,
Steve
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top