Marshal.GetComInterfaceForObject 方法

定義

傳回介面指標,表示物件的介面。

多載

GetComInterfaceForObject(Object, Type)
已淘汰.

傳回 IUnknown 介面指標,表示指定物件上的指定介面。 自訂查詢介面存取預設為啟用。

GetComInterfaceForObject(Object, Type, CustomQueryInterfaceMode)
已淘汰.

傳回 IUnknown 介面指標,表示指定物件上的指定介面。 自訂查詢介面存取是由指定的自訂模式所控制。

GetComInterfaceForObject<T,TInterface>(T)

傳回 IUnknown 介面指標,表示指定類型的物件上的指定介面。 自訂查詢介面存取預設為啟用。

GetComInterfaceForObject(Object, Type)

來源:
Marshal.NoCom.cs
來源:
Marshal.NoCom.cs
來源:
Marshal.NoCom.cs

警告

GetComInterfaceForObject(Object, Type) may be unavailable in future releases. Instead, use GetComInterfaceForObject<T,T2>(T). For more info, go to http://go.microsoft.com/fwlink/?LinkID=296509

傳回 IUnknown 介面指標,表示指定物件上的指定介面。 自訂查詢介面存取預設為啟用。

public:
 static IntPtr GetComInterfaceForObject(System::Object ^ o, Type ^ T);
[System.Obsolete("GetComInterfaceForObject(Object, Type) may be unavailable in future releases. Instead, use GetComInterfaceForObject<T,T2>(T). For more info, go to http://go.microsoft.com/fwlink/?LinkID=296509")]
[System.Security.SecurityCritical]
public static IntPtr GetComInterfaceForObject (object o, Type T);
[System.Runtime.Versioning.SupportedOSPlatform("windows")]
public static IntPtr GetComInterfaceForObject (object o, Type T);
[System.Security.SecurityCritical]
public static IntPtr GetComInterfaceForObject (object o, Type T);
public static IntPtr GetComInterfaceForObject (object o, Type T);
[<System.Obsolete("GetComInterfaceForObject(Object, Type) may be unavailable in future releases. Instead, use GetComInterfaceForObject<T,T2>(T). For more info, go to http://go.microsoft.com/fwlink/?LinkID=296509")>]
[<System.Security.SecurityCritical>]
static member GetComInterfaceForObject : obj * Type -> nativeint
[<System.Runtime.Versioning.SupportedOSPlatform("windows")>]
static member GetComInterfaceForObject : obj * Type -> nativeint
[<System.Security.SecurityCritical>]
static member GetComInterfaceForObject : obj * Type -> nativeint
static member GetComInterfaceForObject : obj * Type -> nativeint
Public Shared Function GetComInterfaceForObject (o As Object, T As Type) As IntPtr

參數

o
Object

提供介面的物件。

T
Type

所要求之介面的類型。

傳回

IntPtr

nativeint

介面指標,表示物件的指定介面。

屬性

例外狀況

T 參數不是介面。

-或-

類型對 COM 為不可見的。

-或-

T 參數是泛型型別定義。

o 參數不支援要求的介面。

o 參數為 null

-或-

T 參數為 null

備註

這個方法會傳回介面指標,表示指定物件上要求的介面。 如果您有預期會傳遞介面指標的 Unmanaged 方法,它特別有用。 使用這個方法呼叫 物件,會導致傳回指標之前,介面指標上的參考計數遞增。 當您完成指標之後,請一律使用 Marshal.Release 來遞減參考計數。 使用原始 COM 介面指標時,您必須遵守 COM 所定義的規則。

GetComInterfaceForObject(Object, Type) 呼叫將 COM 物件參數公開為 IntPtr 型別或自定義封送處理的方法時,很有用。 雖然較不常見,但您可以在Managed物件上使用這個方法,以取得物件的 COM 可呼叫包裝函式的指標。 例如,您可以在 GetComInterfaceForObject(Object, Type) 匯出至 COM 的 Managed 物件上使用 ,以取得 的 System.Runtime.InteropServices.UCOMIConnectionPointContainer介面指標。 您無法取得類別介面的指標,因為類別介面缺少要傳遞至第二個參數的對應型別, (t) 。 請改用 Marshal.GetIDispatchForObject 在 COM 可呼叫包裝函式的預設介面上叫用成員,這通常是自動分派類別介面。

方法 GetComInterfaceForObject(Object, Type) 多載預設允許自定義查詢介面。 若要指定是否要套用查詢介面自定義,請使用 GetComInterfaceForObject(Object, Type, CustomQueryInterfaceMode) 方法多載。

如需詳細資訊,請參閱 COM 可呼叫包裝函 式和 運行時間可呼叫包裝 函式文章。

另請參閱

適用於

GetComInterfaceForObject(Object, Type, CustomQueryInterfaceMode)

來源:
Marshal.NoCom.cs
來源:
Marshal.NoCom.cs
來源:
Marshal.NoCom.cs

警告

GetComInterfaceForObject(Object, Type, CustomQueryInterfaceMode) and support for ICustomQueryInterface may be unavailable in future releases.

傳回 IUnknown 介面指標,表示指定物件上的指定介面。 自訂查詢介面存取是由指定的自訂模式所控制。

public:
 static IntPtr GetComInterfaceForObject(System::Object ^ o, Type ^ T, System::Runtime::InteropServices::CustomQueryInterfaceMode mode);
[System.Obsolete("GetComInterfaceForObject(Object, Type, CustomQueryInterfaceMode) and support for ICustomQueryInterface may be unavailable in future releases.")]
[System.Security.SecurityCritical]
public static IntPtr GetComInterfaceForObject (object o, Type T, System.Runtime.InteropServices.CustomQueryInterfaceMode mode);
[System.Runtime.Versioning.SupportedOSPlatform("windows")]
public static IntPtr GetComInterfaceForObject (object o, Type T, System.Runtime.InteropServices.CustomQueryInterfaceMode mode);
[System.Security.SecurityCritical]
public static IntPtr GetComInterfaceForObject (object o, Type T, System.Runtime.InteropServices.CustomQueryInterfaceMode mode);
public static IntPtr GetComInterfaceForObject (object o, Type T, System.Runtime.InteropServices.CustomQueryInterfaceMode mode);
[<System.Obsolete("GetComInterfaceForObject(Object, Type, CustomQueryInterfaceMode) and support for ICustomQueryInterface may be unavailable in future releases.")>]
[<System.Security.SecurityCritical>]
static member GetComInterfaceForObject : obj * Type * System.Runtime.InteropServices.CustomQueryInterfaceMode -> nativeint
[<System.Runtime.Versioning.SupportedOSPlatform("windows")>]
static member GetComInterfaceForObject : obj * Type * System.Runtime.InteropServices.CustomQueryInterfaceMode -> nativeint
[<System.Security.SecurityCritical>]
static member GetComInterfaceForObject : obj * Type * System.Runtime.InteropServices.CustomQueryInterfaceMode -> nativeint
static member GetComInterfaceForObject : obj * Type * System.Runtime.InteropServices.CustomQueryInterfaceMode -> nativeint
Public Shared Function GetComInterfaceForObject (o As Object, T As Type, mode As CustomQueryInterfaceMode) As IntPtr

參數

o
Object

提供介面的物件。

T
Type

所要求之介面的類型。

mode
CustomQueryInterfaceMode

其中一個列舉值,指出是否要套用 ICustomQueryInterface 所提供的 IUnknown::QueryInterface 自訂。

傳回

IntPtr

nativeint

介面指標,表示物件的介面。

屬性

例外狀況

T 參數不是介面。

-或-

類型對 COM 為不可見的。

-或-

T 參數是泛型型別定義。

物件 o 不支援要求的介面。

o 參數為 null

-或-

T 參數為 null

備註

GetComInterfaceForObject(Object, Type, CustomQueryInterfaceMode) 可讓您指定是否要套用查詢介面自定義。 預設使用 多 GetComInterfaceForObject(Object, Type) 載來套用查詢介面自定義。

適用於

GetComInterfaceForObject<T,TInterface>(T)

來源:
Marshal.NoCom.cs
來源:
Marshal.NoCom.cs
來源:
Marshal.NoCom.cs

傳回 IUnknown 介面指標,表示指定類型的物件上的指定介面。 自訂查詢介面存取預設為啟用。

public:
generic <typename T, typename TInterface>
 static IntPtr GetComInterfaceForObject(T o);
[System.Security.SecurityCritical]
public static IntPtr GetComInterfaceForObject<T,TInterface> (T o);
[System.Runtime.Versioning.SupportedOSPlatform("windows")]
public static IntPtr GetComInterfaceForObject<T,TInterface> (T o);
public static IntPtr GetComInterfaceForObject<T,TInterface> (T o);
[<System.Security.SecurityCritical>]
static member GetComInterfaceForObject : 'T -> nativeint
[<System.Runtime.Versioning.SupportedOSPlatform("windows")>]
static member GetComInterfaceForObject : 'T -> nativeint
static member GetComInterfaceForObject : 'T -> nativeint
Public Shared Function GetComInterfaceForObject(Of T, TInterface) (o As T) As IntPtr

類型參數

T

o 的類型。

TInterface

要傳回的介面類型。

參數

o
T

提供介面的物件。

傳回

IntPtr

nativeint

表示 TInterface 介面的介面指標。

屬性

例外狀況

TInterface 參數不是介面。

-或-

類型對 COM 為不可見的。

-或-

T 參數是開放式泛型類型。

o 參數不支援 TInterface 介面。

o 參數為 null

備註

這個方法會傳回介面指標,表示 TInterface 指定物件上的介面。 如果您有預期會傳遞介面指標的 Unmanaged 方法,它特別有用。 使用這個方法呼叫 物件,會導致傳回指標之前,介面指標上的參考計數遞增。 當您完成指標時,請一律使用 Marshal.Release 方法遞減參考計數。 使用原始 COM 介面指標時,您必須遵守 COM 所定義的規則。

GetComInterfaceForObject<T,TInterface>(T) 呼叫將 COM 物件參數公開為 IntPtr 型別或自定義封送處理的方法時,很有用。 您也可以在 Managed 物件上使用這個方法,以取得物件 COM 可呼叫包裝函式的指標,雖然這較不常見。 例如,您可以在 GetComInterfaceForObject<T,TInterface>(T) 匯出至 COM 的 Managed 物件上使用 ,以取得 的 System.Runtime.InteropServices.UCOMIConnectionPointContainer介面指標。

方法 GetComInterfaceForObject<T,TInterface>(T) 多載預設允許自定義查詢介面。 若要指定是否要套用查詢介面自定義,請使用 GetComInterfaceForObject(Object, Type, CustomQueryInterfaceMode) 方法多載。

如需詳細資訊,請參閱 COM 可呼叫包裝函 式和 運行時間可呼叫包裝 函式文章。

適用於