项目结构
创建Activex步骤:
1.选择创建类别(Windows 控件库或类库)
2.设置对应的com属性
AssemblyInfo.cs中须做以下设置:
a.引入命名空间:using System.Security;
b.[assembly: AllowPartiallyTrustedCallers()]
3.生成的证书能正常在IE下安装,需继承IObjectSafety,考虑到所有的生成的证书都需继承自该接口,需写一个基类,代码如下:
a.接口代码:
using System; using System.Collections.Generic; using System.Text; using System.Runtime.InteropServices; namespace LamSoonActivex { [ComImport, Guid("CB5BDC81-93C1-11CF-8F20-00805F2CD064")] [InterfaceType(ComInterfaceType.InterfaceIsIUnknown)] 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); } }