4 Replies Latest reply on May 23, 2011 5:00 AM by OxleyCreek

    Exposing .net custom control as com

    OxleyCreek

      I want to be able to write a custom control in C# in VS2010 and expose it as a com object so that I can drop it as a control on a Processbook display.

       

      I have ticked "Make Assembly COM visible" and "Register for COM interop" and gone through the "Sign the Assembly"  in my project. What else do I need to do to be able to see the control in the control list in the Processbook build screen?

       

      Thanks

       

      Michael Jones

       

      P.S.

       

      to add the control using VBA is it something like below?

       

       Symbols.Add pbSymbolControl, "{eec32b3d-44de-43f8-a78f-cf3c17983e34}"

       

      I get a "Requested server not found"  error

       

       

       

       

        • Re: Exposing .net custom control as com
          Asle Frantzen

          Hi Michael

           

          I recently made an ActiveX control with .net 4, and there was indeed a lot of bumps in my way.

           

          I would suggest taking a look at Microsoft's All In One Code Framework, located at http://1code.codeplex.com/

           

          In particular, there is a project called CsActiveX which I used as a basis for my control. This project is self installing upon build in Visual Studio (uninstalls through the Clean command for the project), but I found that when I needed to install it through an installer I had to add an "InstallerHelper.cs" file which included this code:

           
          using System;
          using System.Collections.Generic;
          using System.Linq;
          using System.Text;
          using System.Configuration.Install;
          using System.ComponentModel;
          using System.Runtime.InteropServices;
          
          namespace MyNamespace
          {
              [RunInstaller(true)]
              public class ComInstaller : Installer
              {
                  public override void Install(System.Collections.IDictionary stateSaver)
                  {
                      base.Install(stateSaver);
          
                      RegistrationServices regsrv = new RegistrationServices();
                      if (!regsrv.RegisterAssembly(this.GetType().Assembly, AssemblyRegistrationFlags.SetCodeBase))
                      {
                          throw new InstallException("Failed To Register for COM");
                      }
                  }
          
                  public override void Uninstall(System.Collections.IDictionary savedState)
                  {
                      base.Uninstall(savedState);
          
                      RegistrationServices regsrv = new RegistrationServices();
                      if (!regsrv.UnregisterAssembly(this.GetType().Assembly))
                      {
                          throw new InstallException("Failed To Unregister for COM");
                      }
                  }
              }
          }
          

           

           

          And also - for it to work, add a custom action to the installer project for install and uninstall. Just a new "Primary output from ..." even though you've already added that. This actually triggers the bits & pieces in the InstallerHelper.cs I pasted above.