vs2017 C# ActiveX浏览器插件 创建 发布 C# windows窗体控件库(.NET Framework)注意事项

 

  • vs2017需要安装插

 

插件下载地址:https://marketplace.visualstudio.com/items?itemName=VisualStudioProductTeam.MicrosoftVisualStudio2017InstallerProjects#qna

  • 项目创建

 

 

右键项目属性,修改目标框架为.NET Framework 4 Client Profile(用原来的目标框架发布后空间无法调用)
继续修改

 

 

 

 配置大概就这些,接下来码代码

为了让ActiveX控件获得客户端的信任,控件类还需要实现一个名为“IObjectSafety”的接口。

 

namespace UserActiveXDemo
{
    [ComImport, GuidAttribute("F0031FC7-3560-488E-A2AD-7ABC7D85998C")]
    [InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
    public interface IObjectSafety
    {
        [PreserveSig]
        void GetInterfacceSafyOptions(
         int riid,
         out int pdwSupportedOptions,
         out int pdwEnabledOptions);

        [PreserveSig]
        void SetInterfaceSafetyOptions(
        int riid,
        int dwOptionsSetMask,
        int dwEnabledOptions);
    }
}

  用户控件设计

 

 

 

 

用户控件要实现

IObjectSafety接口
namespace UserActiveXDemo
{
    //guid 可以自己定义
    [Guid("685F0A47-944D-4145-BF4E-76A02A422B02")]
    public partial class UserControl1: UserControl, IObjectSafety
    {
        public UserControl1()
        {
            InitializeComponent();
        }
        public void GetInterfacceSafyOptions(int riid, out int pdwSupportedOptions, out int pdwEnabledOptions)
        {
            throw new NotImplementedException();
        }

        public void SetInterfaceSafetyOptions(int riid, int dwOptionsSetMask, int dwEnabledOptions)
        {
            throw new NotImplementedException();
        }
    }
}

  接着是将控件发布

新建项目

 

 

在UserActiveXSetup项目上右键--add--项目输出

 

 点击确定

在主输出文件上右键属性

 

 

 

Register属性修改

 

 

然后生成安装  

在html 页面 添加

 

参考资料

 

 

 

 

<object id="cardReader3" classid="clsid:A075AA8B-DFA7-4741-9FDB-C1B06B0B2D13"
width="500"
height="100"
codebase="CardReader/SetupCardReader/Debug/Setup.exe"></object>
 

 

classid 为 UserControl 顶部的guid
参考大神地址:

http://www.cnblogs.com/yilin/p/csharp-activex.html

源码:链接: https://pan.baidu.com/s/1YvyXLLTQ1QRbMhd9HNrCpw&shfl=shareset 提取码: v5qk

 

 

 



 

 





 

 

posted @ 2019-10-21 16:35  深巷旧夏天  阅读(1065)  评论(0编辑  收藏  举报