[
uuid(CB5BDC81-93C1-11cf-8F20-00805F2CD064),
helpstring("IObjectSafety Interface"),
odl
]
interface IObjectSafety : IUnknown
{
HRESULT GetInterfaceSafetyOptions([in] long riid, [out] long *pdwSupportedOptions, [out] long *pdwEnabledOptions);
HRESULT SetInterfaceSafetyOptions([in] long riid, [in] long dwOptionsSetMask, [in] long dwEnabledOptions);
}
關鍵 IID:{CB5BDC81-93C1-11CF-8F20-00805F2CD064}
using System;
using System.Runtime.InteropServices;
namespace KeyActiveX
{
[ComImport, Guid("CB5BDC81-93C1-11CF-8F20-00805F2CD064")]
[InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
public interface IObjectSafety
{
[PreserveSig]
void GetInterfaceSafetyOptions(int riid, out int pdwSupportedOptions, out int pdwEnabledOptions);
[PreserveSig]
void SetInterfaceSafetyOptions(int riid, int dwOptionsSetMask, int dwEnabledOptions);
}
}
[ComImport]:標示為從 COM 匯入的介面。[Guid(...)]:指定 COM IID,確保身分辨識正確。[InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]:繼承自 IUnknown,僅支援早期繫結。[PreserveSig]:保留原始 HRESULT 回傳值,不自動拋出例外。在 ActiveX 控制項類別中實作 IObjectSafety,並於 SetInterfaceSafetyOptions 中回傳安全選項,讓 IE 認定控制項可安全腳本存取與初始化。