public partial class ReadCardControl : UserControl
其次,为了让ActiveX控件获得客户端的信任,控件类还需要实现一个名为“IObjectSafety”的接口,要创建该接口(注意,不能修改该接口的GUID值),
IObjectSafety代码如下:
[ComImport, Guid("1D9AD540-F2C9-4368-8697-C4AAFCCE9C55")]
[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);
}
注意这里要添加引用:using System.Runtime.InteropServices;
3. 修改控件类,使之继承IObjectSafety接口,代码清单如下:
[Guid("E395359C-86F2-4D7B-A91A-5A64B9E3BA6C")]
public partial class ReadCardControl : UserControl,IObjectSafety
{
public int icdev; // 通讯设备标识符
public Int16 st;
public int sec;
public ReadCardControl()
{
InitializeComponent();
}
#region IObjectSafety 成员
public void GetInterfacceSafyOptions(int riid, out int pdwSupportedOptions, out int pdwEnabledOptions)










