Community
Showing results for 
Search instead for 
Do you mean 
Reply

DLL loads but Button will not run

New Member
Posts: 21
Country: USA

DLL loads but Button will not run

I have a simple DLL that loads a button onto the Opportunities Detail View toolbar. When I click it, it does not run. I wrapped the entire function with a try-catch, but no error shows up.

 

I know the DLL is loaded since the button appears. But Why doesn't the command fire?

 

Here's the code to add the button:

 

 

private void AddMenuIcon()
{
    try
    {
    CommandBarButton NewButton;

    System.Drawing.Image img = (System.Drawing.Image)Properties.Resources.microcad;

    NewButton = new CommandBarButton("Email Quote", "Email Quote", null, "Email Quote", img, img);
    NewButton.DisplayStyle = CommandBarControl.ItemDisplayStyle.ImageOnly;
    NewButton.Text = "Email Quote";

    actApplication.RegisterCommand("Email Quote", CreateItemFromTemplate, RegisterType.Shell);

    try
    {
        for (int i = 0; i <= actApplication.Explorer.CommandBarCollection.Count - 1; i++)
        {
            CommandBar cb = actApplication.Explorer.CommandBarCollection[i];
           if (cb.Type == CommandBarType.Toolbar && !cb.CustomBar && cb.Name.ToUpper() == "Opportunity Detail Toolbar".ToUpper())
            {
                if (!actApplication.Explorer.CommandBarCollection[i].ControlCollection.Contains(NewButton.Command))
                {
                    actApplication.Explorer.CommandBarCollection[i].ControlCollection.Add(NewButton);
                }
              }
           }
        }
        catch
        {
        }
    }
    catch
    {
    }
}

 

Is there anything wrong with how I register the command?

 

It works on the sample database on my dev laptop, but does not fire when running on other computers on the company ACT database.

 

Thanks,

Mike

 

 

Copper Contributor
Posts: 42
Country: Germany

Re: DLL loads but Button will not run

As you and your code say, you've wrapped your entire function into a try-catch statement. So it's no wonder you don't see any error messages. If any exception occurs in the try-part the exception will not be shown to the user and the application won't crash with "unhandled exception" but instead continue with the code in the catch-part which is empty. So you simply suppress any potential error messages that could tell you, what's the problem.

 

For finding the error you could place several "System.Windows.Forms.MessageBox.Show()" outputs in your code so you know, which line executed successfully or the much better approach is to start debugging your code so you can step through line by line from VisualStudio.

Copper Super Contributor
Posts: 52
Country: United_Kingdom

Re: DLL loads but Button will not run

[ Edited ]

Make sure you remove it when closing Act! too. It's possible that if the item already exists and the event isn't being bound to it.

 

Do what twolfram says though, catching exceptions with no action is pretty horrible.

 

Try
{
    //DO YOU THANG!
}
catch (exception ex}
{ MessageBox.Show(ex.Message, this.Text, MessageBoxButtons.OK, MessageBoxIcon.Error); }