activex Getting started with activex

30% OFF - 9th Anniversary discount on Entity Framework Extensions until December 15 with code: ZZZANNIVERSARY9


This section provides an overview of what activex is, and why a developer might want to use it.

It should also mention any large subjects within activex, and link out to the related topics. Since the Documentation for activex is new, you may need to create initial versions of those related topics.

First ActiveX creation guide in Visual Studio C#

Creation Steps

  1. Start Visual Studio 2013 as administrator
  2. Install Visual Studio extension Microsoft Visual Studio Installer Projects
  3. Create a class library project (WinFormActivex)
  4. Create your example window form (MainWindow)
  5. Create a new component interface(ILauncher)
  6. Create a new security interface (IObjectSafety)
  7. Create the component control (Launcher) that implement interfaces and launch the window.
  8. Check that all GUIDs are generated by you
  9. Check that the project is marked for COM
  10. Create the setup project (LauncherInstaller) with the primary output of WinFormActivex with the property Register = vsdrpCOM
  11. Install LauncherInstaller
  12. Run your test page in explorer (test.html)

MainWindow You can create a normal Form, here is pre-generated.

public partial class MainWindow : Form
    public MainWindow()

    /// <summary>
    /// Required designer variable.
    /// </summary>
    private System.ComponentModel.IContainer components = null;

    /// <summary>
    /// Clean up any resources being used.
    /// </summary>
    /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
    protected override void Dispose(bool disposing)
        if (disposing && (components != null))

    #region Windows Form Designer generated code

    /// <summary>
    /// Required method for Designer support - do not modify
    /// the contents of this method with the code editor.
    /// </summary>
    private void InitializeComponent()
        this.textBox1 = new System.Windows.Forms.TextBox();
        this.textBox2 = new System.Windows.Forms.TextBox();
        // textBox1
        this.textBox1.Location = new System.Drawing.Point(42, 23);
        this.textBox1.Name = "textBox1";
        this.textBox1.Size = new System.Drawing.Size(100, 20);
        this.textBox1.TabIndex = 0;
        // textBox2
        this.textBox2.Location = new System.Drawing.Point(42, 65);
        this.textBox2.Name = "textBox2";
        this.textBox2.Size = new System.Drawing.Size(100, 20);
        this.textBox2.TabIndex = 0;
        // MainWindow
        this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
        this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
        this.ClientSize = new System.Drawing.Size(284, 261);
        this.Name = "MainWindow";
        this.Text = "MainWindow";



    private System.Windows.Forms.TextBox textBox1;
    private System.Windows.Forms.TextBox textBox2;


using System.Runtime.InteropServices;
namespace WinFormActivex
    public interface ILauncher
        void ShowWindow();


interface IObjectSafety
    int GetInterfaceSafetyOptions(ref Guid riid, out int pdwSupportedOptions, out int pdwEnabledOptions);
    int SetInterfaceSafetyOptions(ref Guid riid, int dwOptionSetMask, int dwEnabledOptions);

Launcher Please generate your GUID here.

 public class Launcher : UserControl, ILauncher, IObjectSafety
     #region [ ILauncher ]

     public void ShowWindow()
         var f = new MainWindow();
         f.StartPosition = FormStartPosition.Manual;
         f.Location = Screen.AllScreens[0].Bounds.Location;
         f.WindowState = FormWindowState.Normal;
         f.WindowState = FormWindowState.Maximized;
         f.ShowInTaskbar = false;


     #region [ IObjectSafety ]

     public enum ObjectSafetyOptions
         INTERFACE_USES_DISPEX = 0x00000004,

     public int GetInterfaceSafetyOptions(ref Guid riid, out int pdwSupportedOptions, out int pdwEnabledOptions)
         ObjectSafetyOptions m_options = ObjectSafetyOptions.INTERFACESAFE_FOR_UNTRUSTED_CALLER | ObjectSafetyOptions.INTERFACESAFE_FOR_UNTRUSTED_DATA;
         pdwSupportedOptions = (int)m_options;
         pdwEnabledOptions = (int)m_options;
         return 0;

     public int SetInterfaceSafetyOptions(ref Guid riid, int dwOptionSetMask, int dwEnabledOptions)
         return 0;


test.html Please check that your CLSID match (Launcher) GUID.

        <objectname="activexLauncher" style='display:none' id='activexLauncher' classid='CLSID:D100C392-030A-411C-92B6-4DBE9AC7AA5A' codebase='WinFormActivex'></object>
      <script language="javascript">
        <!-- Load the ActiveX object  -->
        var x = new ActiveXObject("WinFormActivex.Launcher");


Got any activex Question?