views:

18

answers:

0

there's a problem in attaching an addin to powerpoint using following code

public void OnStartupComplete(ref System.Array custom)
    {
        CommandBars oCommandBars;
        CommandBar oStandardBar;

        try
        {
            oCommandBars = (CommandBars)applicationObject.GetType().InvokeMember("CommandBars", BindingFlags.GetProperty, null, applicationObject, null);
        }
        catch (Exception)
        {

            object oActiveExplorer;
            oActiveExplorer = applicationObject.GetType().InvokeMember("ActiveExplorer", BindingFlags.GetProperty, null, applicationObject, null);

oCommandBars = (CommandBars)oActiveExplorer.GetType().InvokeMember("CommandBars", BindingFlags.GetProperty, null, oActiveExplorer, null); }

        // Set up a custom button on the "Standard" commandbar.
        try
        {
            oStandardBar = oCommandBars["Standard"];
        }
        catch (Exception)
        {
            // Access names its main toolbar Database.
            oStandardBar = oCommandBars["Database"];
        }

        // In case the button was not deleted, use the exiting one.
        try
        {
            MyButton = (CommandBarButton)oStandardBar.Controls["My Custom Button"];
        }
        catch (Exception)
        {
            object omissing = System.Reflection.Missing.Value;

MyButton = (CommandBarButton)oStandardBar.Controls.Add(1, omissing, omissing, omissing, omissing); MyButton.Caption = "My Custom Button"; MyButton.Style = MsoButtonStyle.msoButtonCaption; }

        MyButton.Tag = "My Custom Button";

        MyButton.OnAction = "!<MyAddin2.Connect>";

        MyButton.Visible = true;
        MyButton.Click += new Microsoft.Office.Core._CommandBarButtonEvents_ClickEventHandler(this.MyButton_Click);

object oName = applicationObject.GetType().InvokeMember("Name", BindingFlags.GetProperty, null, applicationObject, null);

System.Windows.Forms.MessageBox.Show("This Addin is loaded by " + oName.ToString(), "MyAddin2"); oStandardBar = null; oCommandBars = null; }

this code is compiling well , but not creating button on standard bar of MS Powerpoint.