public void OnDisconnect()
 {
     // This method is called as Minitab is closing your add-in.
     GC.Collect();
     GC.WaitForPendingFinalizers();
     try
     {
         Marshal.FinalReleaseComObject(AddIn.gMtbApp);
         AddIn.gMtbApp = null;
     }
     catch
     {
     }
     return;
 }
 public void OnConnect(Int32 iHwnd, Object pApp, ref Int32 iFlags)
 {
     // This method is called as Minitab is initializing your add-in.
     // The “iHwnd” parameter is the handle to the main Minitab window.
     // The “pApp” parameter is a reference to the “Minitab Automation object.”
     // You can hold onto either of these for use in your add-in.
     // “iFlags” is used to tell Minitab if your add-in has dynamic menus (i.e. should be reloaded each time
     // Minitab starts up).  Set Flags to 1 for dynamic menus and 0 for static.
     AddIn.gMtbApp = pApp as Mtb.Application;
     // This forces Minitab to retain all commands (even those run by the interactive user):
     AddIn.gMtbApp.Options.SaveCommands = true;
     // Static menus:
     iFlags = 0;
     return;
 }