-
vs2017需要安裝插
-
項目創建
右鍵項目屬性,修改目標框架為.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