ActiveX control inside PowerPoint slide

0

I've created a very simple program and exposed it as an ActiveX Control. What I'm trying to do is to embed this control into a PowerPoint slide. The code for the program is as follows:

namespace WindowsFormsApplication1
{
    [ProgId("Tomor.Form1")]
    [ClassInterface(ClassInterfaceType.AutoDispatch)]
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            button1.Text = "Clicked";
        }
    }
}

I've cheked the Make the assembly COM-visible and also checked the Register for COM-interop. I've also implemented the RegisterClass and UnregisterClass methods (but haven't shown here, see this, for an exact implementation), and have been able to successfully register it using regasm.exe. I'm also able to access the interface from another project using Tomor1.Form. Now, I am trying to insert this control into a PowerPoint slide as follows:

      PowerPoint.Shape s = Sld.Shapes.AddOLEObject(0, 0, 400, 400, "Tomor.Form1");

However, all I am getting is the following error upon startup:

  • $exception {"Could not read key from registry (Exception from HRESULT: 0x80040150 (REGDB_E_READREGDB))"} System.Exception {System.Runtime.InteropServices.COMException}

The interesting thing is that I can see the "key" in registry by navigating to: Compuer\HKEY_CLASSES_ROOT\Tomor1.Form\CLSID

c#
.net
powerpoint
office-interop
asked on Stack Overflow Aug 31, 2013 by tomor

1 Answer

0

Even though I'm not quite sure, I suspect that the problem must be with ComRegisterFunction. I've found another implementation somewhere else, and with that implementation, the assembly is registered correctly, and can be accessed from PowerPoint. The implementation for the ComRegisterFunction is as follows:

    [ComRegisterFunction]
    static void ComRegister(Type t)
    {
        string keyName = @"CLSID\" + t.GUID.ToString("B");
        using (RegistryKey key =
            Registry.ClassesRoot.OpenSubKey(keyName, true))
        {
            key.CreateSubKey("Control").Close();
            using (RegistryKey subkey = key.CreateSubKey("MiscStatus"))
            {
                // 131456 decimal == 0x20180.
                long val = (long)
                    (OLEMISC.OLEMISC_INSIDEOUT
                    | OLEMISC.OLEMISC_ACTIVATEWHENVISIBLE
                    | OLEMISC.OLEMISC_SETCLIENTSITEFIRST);
                subkey.SetValue("", val);
            }
            using (RegistryKey subkey = key.CreateSubKey("TypeLib"))
            {
                Guid libid =
                    Marshal.GetTypeLibGuidForAssembly(t.Assembly);
                subkey.SetValue("", libid.ToString("B"));
            }
            using (RegistryKey subkey = key.CreateSubKey("Version"))
            {
                Version ver = t.Assembly.GetName().Version;
                string version =
                  string.Format("{0}.{1}", ver.Major, ver.Minor);
                subkey.SetValue("", version);
            }
        }
    }
answered on Stack Overflow Sep 12, 2013 by tomor

User contributions licensed under CC BY-SA 3.0