Develop ActiveX controls and create CAB packages

Source: Internet
Author: User

ActiveX controls are used in a project. by referring to the numerous examples on the internet, ActiveX controls are easily implemented;
Then I made a [installation project], which can be used, but I only need to manually click Install On the client. Next, next... I think it is not very nice;
I tried the [CAB project] Again. It seems that no one uses VS2008. After a little effort, I finally found a solution.
We will share this experience with you.

Development tools: Visual Studio 2008
. NET: 2.0
Development language: C #

I. Compile ActiveX Controls
1. Create a Windows Forms control library project]

2. Add a [user control]

3. Drag two Label controls to the interface

4. Add a method for the control to display the current time in the Label.

 

 /// <Summary>
/// Set the current time
/// </Summary>
/// <Param name = "timeStr"> </param>
Public void SetTime (string timeStr)
{
This. label2.Text = timeStr;
}

 

 

 

5. Create an interface:
It is said that the purpose of this interface is to improve program security so that the client IE can pre-execute the ActiveX control without changing the settings.
For this article, we recommend that you:

Http://blog.csdn.net/optman/archive/2007/07/18/1698070.aspx

 

 using System;
using System.Collections.Generic;
using System.Text;
using System.Runtime.InteropServices;

namespace HelloBossma
{
[ComImport, GuidAttribute("CB5BDC81-93C1-11CF-8F20-00805F2CD064")]
[InterfaceTypeAttribute(ComInterfaceType.InterfaceIsIUnknown)]
public interface IObjectSafety
{
[PreserveSig]
int GetInterfaceSafetyOptions(ref Guid riid, [MarshalAs(UnmanagedType.U4)] ref int pdwSupportedOptions, [MarshalAs(UnmanagedType.U4)] ref int pdwEnabledOptions);

[PreserveSig()]
int SetInterfaceSafetyOptions(ref Guid riid, [MarshalAs(UnmanagedType.U4)] int dwOptionSetMask, [MarshalAs(UnmanagedType.U4)] int dwEnabledOptions);
}
}

6. Let our controls implement this interface.
For a long time to implement this interface, you can find it in this article:

Http://www.pinvoke.net/default.aspx/Interfaces/IObjectSafety.html

7. Add the Guid, ProgId, and ComVisible attributes for our controls.

 

 namespace HelloBossma
{
[Guid("636B8CE1-7512-464C-B63C-FC75BDCA21DB"), ProgId("HelloBossma.HelloBossmaActiveX"), ComVisible(true)]
public partial class HelloBossmaActiveX : UserControl, IObjectSafety
{
...
}
}

 

 

 

8. Open the project properties, and check [Register for Com interoperability] In the generate process]

9. Create a project and go to the binRelease directory.
HelloBossma. dll
HelloBossma. tlb
These two files are required; otherwise, they are not generated successfully.

 

 

 

 

2. Create an ActiveX Setup Installation File
1. Create an installation project

2. Right-click the project, choose add> project output, and select the project above.

3. Open the properties page of the installation project and set the installation URL.
Set http: // localhost/hellobossma
This directory must actually exist to store the generated installation files for the client to download and install.

4. Generate a project
Two files, one exe file and one msi file are generated.

5. Create a website and add the following code to the webpage.
Classid is the Guid of the control.

 

 
Related Article

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.