首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
您现在的位置: 程式碼之家 >> 編程語言 >  >> C語言 >> 關於C語言

C# 開發 ActiveX 控制項 實戰(三):IObjectSafety 介面實作

     編輯:關於C語言

IObjectSafety 介面定義 (IDL)


[
  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}

C# 實作 IObjectSafety


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 認定控制項可安全腳本存取與初始化。

  1. 上一篇文章:
  2. 下一篇文章:
Copyright © 程式碼之家 All Rights Reserved