Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Outlook / Programming Add-Ins / May 2004

Tip: Looking for answers? Try searching our database.

Problem with attaching to reply button

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Jessica Holtz - 20 May 2004 19:15 GMT
Hi all!

I'm hoping that someone can help me with a problem I'm having! :)

I'm trying to attach to the reply button in Outlook 2003 with C#, but I'm
getting an exception thrown everytime I try to access a commandbar, such as
"Standard"!

My code looks like:

private static Outlook.Application oApplication;
private static Microsoft.Office.Core.CommandBarButton cbExplReply;

....
public void OnConnection(object application, Extensibility.ext_ConnectMode
connectMode, object addInInst, ref System.Array custom)
{
try
{
oApplication = (Outlook.Application)application;
Microsoft.Office.Core.CommandBar cbStandard =
(Microsoft.Office.Core.CommandBar)oApplication.ActiveExplorer().CommandBars[
"Standard"];  //Exception thrown on this line
cbExplReply =
(Microsoft.Office.Core.CommandBarButton)cbStandard.Controls["Reply"];
cbExplReply.Click += new
Microsoft.Office.Core._CommandBarButtonEvents_ClickEventHandler(OnToolbarBut
tonClick);
}catch( Exception ex )
{
System.Windows.Forms.MessageBox.Show( ex.ToString() );
}
}

 private static void OnToolbarButtonClick(CommandBarButton cmdBarbutton,ref
bool cancel)
 {

  System.Windows.Forms.MessageBox.Show("Hello World","Jessica Addin");

 }

This throws a:
System.NullReferenceException: Object reference not set to an instance of an
object.
  at MyAddinJessica.Connect.OnConnection(Object application,
ext_ConnectMode connectMode, Object addInInst, Array& custom) in
c:\implementation\source_code\interface\connect.cs:line 178

Thanks Much!
Jessica
Jessica Holtz - 28 May 2004 17:39 GMT
I needed to use Reflection to bind to the CommandBars object in the
ActiveExplorer:

    oActiveExplorer=
oApplication.GetType().InvokeMember("ActiveExplorer",BindingFlags.GetPropert
y,null,oApplication,null);
    oCommandBars=
(Office.CommandBars)oActiveExplorer.GetType().InvokeMember("CommandBars",Bin
dingFlags.GetProperty,null,oActiveExplorer,null);
    oStandardBar = oCommandBars["Standard"];
    cbExplReply =
(Microsoft.Office.Core.CommandBarButton)oStandardBar.Controls["Reply"];
    cbExplReply.Click += new
Microsoft.Office.Core._CommandBarButtonEvents_ClickEventHandler(OnToolbarBut
tonClick);

Does anyone know why I needed to use Reflection?

Thanks,
Jessica

> Hi all!
>
[quoted text clipped - 17 lines]
> oApplication = (Outlook.Application)application;
> Microsoft.Office.Core.CommandBar cbStandard =

(Microsoft.Office.Core.CommandBar)oApplication.ActiveExplorer().CommandBars[
> "Standard"];  //Exception thrown on this line
> cbExplReply =
> (Microsoft.Office.Core.CommandBarButton)cbStandard.Controls["Reply"];
> cbExplReply.Click += new

Microsoft.Office.Core._CommandBarButtonEvents_ClickEventHandler(OnToolbarBut
> tonClick);
> }catch( Exception ex )
[quoted text clipped - 20 lines]
> Thanks Much!
> Jessica
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.