win7下VS2010CActiveX控件制作打包测试.docVIP

  • 10
  • 0
  • 约4.39千字
  • 约 13页
  • 2017-08-11 发布于重庆
  • 举报
win7下VS2010CActiveX控件制作打包测试

环境: 操作系统:Win7 开发工具:Visual Studio 2010 .NET版本:4.0 开发语言:C# 下载makeCAB压缩包,这里面包含了制作数字签名和制作cab的几个exe程序 保存路径:D:\makeCAB 需要编辑的系统环境变量设置:(下面的系统变量) 这样做是为了方便后面在cmd里调用。 二、编写ActiveX控件 1、创建一个新的Windows窗体控件库 2、重命名UserControl1.cs 为HelloDanielActiveX.cs 3、拖1个GroupBox和2个Label控件到界面上 4、为控件添加一个方法,用来设置Label中显示当前时间 #region Javascript调用ActiveX的方法 // 设置当前时间 public void SetTime(string timeStr) { this.label2.Text = timeStr; } #endregion 5、新建一个接口 下面是这个接口的代码: using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Runtime.InteropServices; namespace HelloDaniel { [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、在控件中实现这个接口 关于实现这个接口,篇幅较长,可以在这篇文章找到:/default.aspx/Interfaces/IObjectSafety.html [Guid(6DCD51C2-33FD-4556-842F-419B6AA3C252), ProgId(HelloDaniel.HelloDanielActiveX), ComVisible(true)] public partial class HelloDanielActiveX : UserControl, IObjectSafety { private const string _IID_IDispatch = 0000-0000-C000-000000000046}; private const string _IID_IDispatchEx = {a6ef9860-c720-11d0-9337-00a0c90dcaa9}; private const string _IID_IPersistStorage = {0000010A-0000-0000-C000-000000000046}; ………………中间是接口实现的代码,参考上面的网址拷贝一下即可。 } } 8、为了实现在控件中javascript的调用,需要添加引入 右键单击项目HelloDaniel——【添加引用】 控件代码的头文件需要添加的是: using System; using System.Collections.Generic; using System.ComponentModel; using System.Drawing; using System.Data; using System.

文档评论(0)

1亿VIP精品文档

相关文档