文档详情

CActiveX控件开发,打包cab安装部署,含源码及全过程开发文档.doc

发布:2017-08-08约8.38千字共9页下载文档
文本预览下载声明
1. 问题场景 在C/S架构的系统中,客户端要实现某些业务功能,可以通过安装相关的应用程序集来方便的实现。同样的需求,在B/S架构的系统里实现起来却比较困难。因为所有的程序都放在服务器端,客户端只是采用浏览器,通过HTTP协议来访问服务器端。比较成熟的解决办法是开发ActiveX控件安装到客户端,这样客户端的浏览器就可以访问本地的ActiveX控件来执行相关的本地操作。通常开发ActiveX使用C,C++或VB开发,本文将要谈论的,就是使用C#开发一个ActiveX控件。 3. 注意的地方,C#开发的ActiveX控件只可在装有Framework的系统上才能用。 2. 开发工具Visual Studio 2010 .NET版本:2.0开发语言:C#[Guid(DF0769A5-99D3-4BE0-90B8-91C65A92118C), ProgId(ActiveXDemo.MiugoX), ComVisible(true)] public partial class MiugoX : UserControl, IObjectSafety { …… // DF0769A5-99D3-4BE0-90B8-91C65A92118C就¨a是o?刚?刚?创???建?§的ì?Guid IObjectSafety,实现该接口的目的就是提高程序的安全性,以便客户端IE在不更改设置的情况下可以预行该ActiveX控件。接口成员如下: using System; using System.Runtime.InteropServices; namespace ActiveXDemo { [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); } } (4),用户控件MiugoX.cs需要继承并实现IObjectSafety接口,需要引用using System.Security.Cryptography和using System.Runtime.InteropServices;两个命名空间 Miiugo.cs实现的接口成员如下: using System; using System.ComponentModel; using System.Drawing; using System.Windows.Forms; using System.IO; using System.Text; using System.Security.Cryptography; using System.Runtime.InteropServices; namespace ActiveXDemo { [Guid(DF0769A5-99D3-4BE0-90B8-91C65A92118C), ProgId(ActiveXDemo.MiugoX), ComVisible(true)] public partial class MiugoX : UserControl, IObjectSafety { #region IObjectSafety 成员 private const string _IID_IDispatch = 0000-0000-C000-000000000046}; private const string _IID_IDispatchEx = {a6ef9860-c720-11d0-9337-00a0c90dca
显示全部
相似文档