See example:
using System;
using System.Collections;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Windows.Forms;
// Add in these using clauses for this example
using System.Runtime.InteropServices;
using System.Text;
using System.Reflection;
using Microsoft.Win32;
namespace WinCtrlLib1
{
/// <summary>
/// Summary description for UserControl1.
/// </summary>
[Guid("CE41F576-F0C9-4509-B1B6-BD710DA329CA")]
[ProgId("WinCtrlLib1.UserCtrl1")]
[ClassInterface(ClassInterfaceType.AutoDual)]
public class UserCtrl1 : System.Windows.Forms.UserControl
{
private System.Windows.Forms.TextBox txtBox;
private System.Windows.Forms.Button btnOK;
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.Container components = null;
public UserCtrl1()
{
// This call is required by the Windows.Forms Form Designer.
InitializeComponent();
// TODO: Add any initialization after the InitComponent call
}
/// <summary>
/// Clean up any resources being used.
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if( components != null )
components.Dispose();
}
base.Dispose( disposing );
}
#region Component 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.txtBox = new System.Windows.Forms.TextBox();
this.btnOK = new System.Windows.Forms.Button();
this.SuspendLayout();
//
// txtBox
//
this.txtBox.Location = new System.Drawing.Point(24, 24);
this.txtBox.Name = "txtBox";
this.txtBox.Size = new System.Drawing.Size(104, 20);
this.txtBox.TabIndex = 0;
this.txtBox.Text = "";
//
// btnOK
//
this.btnOK.Location = new System.Drawing.Point(40, 64);
this.btnOK.Name = "btnOK";
this.btnOK.TabIndex = 1;
this.btnOK.Text = "OK";
this.btnOK.Click += new System.EventHandler(this.btnOK_Click);
//
// UserCtrl1
//
this.Controls.Add(this.btnOK);
this.Controls.Add(this.txtBox);
this.Name = "UserCtrl1";
this.Size = new System.Drawing.Size(150, 104);
this.ResumeLayout(false);
}
#endregion
[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") )
{
subkey.SetValue("", "131457");
}
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);
if( version == "0.0" ) version = "1.0";
subkey.SetValue("", version);
}
}
}
[ComUnregisterFunction]
static void ComUnregister(Type t)
{
// Delete entire CLSID\{clsid} subtree
string keyName = @"CLSID\" + t.GUID.ToString("B");
Registry.ClassesRoot.DeleteSubKeyTree(keyName);
}
private void btnOK_Click(object sender, System.EventArgs e)
{
MessageBox.Show(this.txtBox.Text);
}
}
}
> Hello,
>
[quoted text clipped - 4 lines]
>
> Petrica