Implementing ActiveX Control development with C #

Source: Internet
Author: User
Tags implement visual studio

To implement an ActiveX control using C #, three issues need to be resolved:

1. Enable. NET components to be invoked by COM

2. After registering with the client, the ActiveX control can be authenticated by IE security

3. When not registered on the client, the installation package can be authenticated by IE's signature

The development environment for this program is. NET Framework 3.5, a tool that is visual Studio. NET 2008, passing tests on clients that have installed the. NET Framework 3.5.

Here is the implementation step:

(i) Create an assembly that can be accessed from COM

First implement a COM-visible assembly, create a class library project, AssemblyInfo.cs should include:

using System.Runtime.InteropServices;
//使此程序集中的类型对COM组件可见
[assembly: ComVisible(true)]
// 如果此项目向 COM 公开,则下列 GUID 用于类型库的 ID
[assembly: Guid("94882155-3B7C-48e3-B357-234D56D8F15E")]

Add the following code to AssemblyInfo.cs to ensure the accessibility of the assembly:

using System.Security;
[assembly: AllowPartiallyTrustedCallers()]

Note the GUID above, if the class inside the assembly is not annotated guid,com the registered GUID is newly generated and the GUID here is not useful.

Create a user control (custom class to be measured) IdentityKey.cs, join:

using System;
using System.ComponentModel;
using System.Windows.Forms;
using System.Runtime.InteropServices;
namespace KeyActiveX
{
[Guid("94882155-3B7C-48e3-B357-234D56D8F15E")]
public partial class IdentityKey : UserControl
{
}
}

The GUID here is the same as the AssemblyInfo.cs, which becomes a CLSID in COM registration and is invoked by the HTML as a CLSID.

Class Library project Properties, select Build, tick COM registration, add in HTML file

<object id="controlbyid" classid="clsid:{94882155-3B7C-48e3-B357 -234D56D8F15E}" ></object>

When you enable unsafe controls in IE, view HTML pages, you should be able to access the control, and now an assembly is developed for COM registration at publication time.

You can view the components and CLSID in. NET categories using the Ole/com Object Viewer, which is installed with the VC self.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.