博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
C# 编写ActiveX
阅读量:4356 次
发布时间:2019-06-07

本文共 1715 字,大约阅读时间需要 5 分钟。

1. 新建 WindowFormControlLibrary

2. 修改 项目->右键属性->Application-> Assembly Information ->勾选 Make Assembly Com-Visible

3. 修改 项目->右键属性-> Build -> 勾选 Register for Com interop 

4. 控件cs界面, using System.Runtime.InteropServices 命名空间; 类名添加 GUID属性

using System;using System.Collections.Generic;using System.ComponentModel;using System.Drawing;using System.Data;using System.Linq;using System.Text;using System.Windows.Forms;using System.Runtime.InteropServices;namespace MyActiveX2{    [Guid("07333C44-7CFD-3C64-A540-C476FE80EEF2")]    public partial class demo : UserControl, IObjectSafety    { .....

 

5. 继承IObjectSafety 接口

#region IObjectSafety Members        public void GetInterfacceSafyOptions(int riid, out int pdwSupportedOptions, out int pdwEnabledOptions)        {            pdwSupportedOptions = 1;            pdwEnabledOptions = 2;        }        public void SetInterfaceSafetyOptions(int riid, int dwOptionsSetMask, int dwEnabledOptions)        {            //throw new NotImplementedException();        }        #endregion
using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Runtime.InteropServices;namespace MyActiveX2{    [Guid("CB5BDC81-93C1-11CF-8F20-00805F2CD064"), InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]    public interface IObjectSafety    {        void GetInterfacceSafyOptions(System.Int32 riid, out System.Int32 pdwSupportedOptions, out System.Int32 pdwEnabledOptions);        void SetInterfaceSafetyOptions(System.Int32 riid, System.Int32 dwOptionsSetMask, System.Int32 dwEnabledOptions);    }}

6. 网页引用就可以了

          

7. 安装程序

新建项目-> 安装项目 -> Appliction Folder -> 添加 项目的主输出,并设置Register属性为vsdrpCOM.

 

转载于:https://www.cnblogs.com/machaofast/p/3222553.html

你可能感兴趣的文章
小D课堂 - 零基础入门SpringBoot2.X到实战_第11节 Logback日志框架介绍和SpringBoot整合实战_45、SpringBoot2.x日志讲解和Logback配置实战...
查看>>
类中的静态函数和非静态函数的区别
查看>>
windows 下安装Apache
查看>>
Fedora14 mount出现错误时解决办法【亲测有效】
查看>>
使用Visual Studio 2013进行UI自动化测试
查看>>
13-集体照
查看>>
读了曾国藩家书,,心态逐渐平和起来。搞技术的如果缺乏信念的指引,生活会很乏味无聊!...
查看>>
160809308周子济第六次作业
查看>>
sublime text3最新版本注册码(build 3143)
查看>>
linux使用技巧
查看>>
必背公式及常数
查看>>
利用CSS、JavaScript及Ajax实现图片预加载的三大方法
查看>>
js时间戳转时间格式
查看>>
Nginx配置文件nginx.conf中文详解(总结)
查看>>
Linux的用户态和内核态
查看>>
JavaScript原生错误及检测
查看>>
(原创) cocos2d-x 3.0+ lua 学习和工作(4) : 公共函数(3): 深度克隆clone()
查看>>
为什么写作
查看>>
整数子数组求最大和添加验证
查看>>
使用kubeadm安装Kubernetes
查看>>