C# 编写ActiveX

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. 网页引用就可以了

   <object id="obj1" classid="clsid:07333C44-7CFD-3C64-A540-C476FE80EEF2" >      
    </object>

7. 安装程序

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

 

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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值