项目结构
C#开发Activex控件(1)

创建Activex步骤:

1.选择创建类别(Windows 控件库或类库)
C#开发Activex控件(1)

2.设置对应的com属性
C#开发Activex控件(1)

C#开发Activex控件(1)

AssemblyInfo.cs中须做以下设置:
a.引入命名空间:using System.Security;
b.[assembly: AllowPartiallyTrustedCallers()]

C#开发Activex控件(1)

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);
    }
}
View Code

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-12-06
  • 2022-12-23
猜你喜欢
  • 2021-05-10
  • 2021-06-11
  • 2021-08-25
  • 2021-12-15
  • 2022-02-11
相关资源
相似解决方案