Marshal.GetComInterfaceForObject Metodo

Definizione

Restituisce un puntatore a interfaccia che rappresenta un'interfaccia per un oggetto.

Overload

GetComInterfaceForObject(Object, Type)
Obsoleti.

Restituisce un puntatore a un'interfaccia IUnknown che rappresenta l'interfaccia specificata sull'oggetto specificato. L'accesso all'interfaccia di query è abilitato per impostazione predefinita.

GetComInterfaceForObject(Object, Type, CustomQueryInterfaceMode)
Obsoleti.

Restituisce un puntatore a un'interfaccia IUnknown che rappresenta l'interfaccia specificata sull'oggetto specificato. L'accesso all'interfaccia di query personalizzato viene controllato dalla modalità della personalizzazione specificata.

GetComInterfaceForObject<T,TInterface>(T)

Restituisce un puntatore a un'interfaccia IUnknown che rappresenta l'interfaccia specificata sull'oggetto del tipo specificato. L'accesso all'interfaccia di query è abilitato per impostazione predefinita.

GetComInterfaceForObject(Object, Type)

Origine:
Marshal.NoCom.cs
Origine:
Marshal.NoCom.cs
Origine:
Marshal.NoCom.cs

Attenzione

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

Restituisce un puntatore a un'interfaccia IUnknown che rappresenta l'interfaccia specificata sull'oggetto specificato. L'accesso all'interfaccia di query è abilitato per impostazione predefinita.

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

Parametri

o
Object

Oggetto che fornisce l'interfaccia.

T
Type

Tipo di interfaccia richiesto.

Restituisce

IntPtr

nativeint

Puntatore a interfaccia che rappresenta l'interfaccia specificata per l'oggetto.

Attributi

Eccezioni

Il parametro T non è un'interfaccia.

-oppure-

Il tipo non è visibile a COM.

-oppure-

Il parametro T è una definizione di tipo generico.

Il parametro o non supporta l'interfaccia richiesta.

Il valore del parametro o è null.

-oppure-

Il valore del parametro T è null.

Commenti

Questo metodo restituisce un puntatore dell'interfaccia che rappresenta l'interfaccia richiesta nell'oggetto specificato. È particolarmente utile se si dispone di un metodo non gestito che prevede di passare un puntatore dell'interfaccia. La chiamata di un oggetto con questo metodo causa l'incremento del conteggio dei riferimenti sul puntatore dell'interfaccia prima che venga restituito il puntatore. Usare Marshal.Release sempre per decrerere il conteggio dei riferimenti dopo aver completato il puntatore. È necessario rispettare le regole definite da COM quando si usano puntatori di interfaccia COM non elaborati.

GetComInterfaceForObject(Object, Type) è utile quando si chiama un metodo che espone un parametro dell'oggetto COM come IntPtr tipo o con il marshalling personalizzato. Sebbene meno comune, è possibile usare questo metodo in un oggetto gestito per ottenere un puntatore al wrapper chiamabile COM dell'oggetto. Ad esempio, è possibile usare GetComInterfaceForObject(Object, Type) in un oggetto gestito esportato in COM per ottenere un puntatore dell'interfaccia per System.Runtime.InteropServices.UCOMIConnectionPointContainer. Non è possibile ottenere un puntatore a un'interfaccia di classe poiché un'interfaccia di classe manca del tipo corrispondente per passare al secondo parametro (t). Usare Marshal.GetIDispatchForObject invece per richiamare i membri nell'interfaccia predefinita del wrapper chiamabile COM, che in genere è un'interfaccia di classe di invio automatico.

L'overload del metodo consente la personalizzazione dell'interfaccia GetComInterfaceForObject(Object, Type) di query per impostazione predefinita. Per specificare se applicare la personalizzazione dell'interfaccia di query, usare l'overload del GetComInterfaceForObject(Object, Type, CustomQueryInterfaceMode) metodo.

Per altre informazioni, vedere gli articoli COM Callable Wrapper e Runtime Callable Wrapper.

Vedi anche

Si applica a

GetComInterfaceForObject(Object, Type, CustomQueryInterfaceMode)

Origine:
Marshal.NoCom.cs
Origine:
Marshal.NoCom.cs
Origine:
Marshal.NoCom.cs

Attenzione

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

Restituisce un puntatore a un'interfaccia IUnknown che rappresenta l'interfaccia specificata sull'oggetto specificato. L'accesso all'interfaccia di query personalizzato viene controllato dalla modalità della personalizzazione specificata.

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

Parametri

o
Object

Oggetto che fornisce l'interfaccia.

T
Type

Tipo di interfaccia richiesto.

mode
CustomQueryInterfaceMode

Uno dei valori di enumerazione che indica se applicare una personalizzazione IUnknown::QueryInterface fornita da un oggetto ICustomQueryInterface.

Restituisce

IntPtr

nativeint

Puntatore a interfaccia che rappresenta l'interfaccia per l'oggetto.

Attributi

Eccezioni

Il parametro T non è un'interfaccia.

-oppure-

Il tipo non è visibile a COM.

-oppure-

Il parametro T è una definizione di tipo generico.

Il parametro o dell'oggetto non supporta l'interfaccia richiesta.

Il valore del parametro o è null.

-oppure-

Il valore del parametro T è null.

Commenti

GetComInterfaceForObject(Object, Type, CustomQueryInterfaceMode) consente di specificare se applicare la personalizzazione dell'interfaccia di query. Usare l'overload per applicare la personalizzazione dell'interfaccia GetComInterfaceForObject(Object, Type) di query per impostazione predefinita.

Si applica a

GetComInterfaceForObject<T,TInterface>(T)

Origine:
Marshal.NoCom.cs
Origine:
Marshal.NoCom.cs
Origine:
Marshal.NoCom.cs

Restituisce un puntatore a un'interfaccia IUnknown che rappresenta l'interfaccia specificata sull'oggetto del tipo specificato. L'accesso all'interfaccia di query è abilitato per impostazione predefinita.

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

Parametri di tipo

T

Tipo di o.

TInterface

Tipo di interfaccia da restituire.

Parametri

o
T

Oggetto che fornisce l'interfaccia.

Restituisce

IntPtr

nativeint

Puntatore a interfaccia che rappresenta l'interfaccia TInterface.

Attributi

Eccezioni

Il parametro TInterface non è un'interfaccia.

-oppure-

Il tipo non è visibile a COM.

-oppure-

Il parametro T è un tipo generico aperto.

Il parametro o non supporta l'interfaccia TInterface.

Il valore del parametro o è null.

Commenti

Questo metodo restituisce un puntatore dell'interfaccia che rappresenta l'interfaccia nell'oggetto TInterface specificato. È particolarmente utile se si dispone di un metodo non gestito che prevede di passare un puntatore dell'interfaccia. La chiamata di un oggetto con questo metodo causa l'incremento del conteggio dei riferimenti sul puntatore dell'interfaccia prima che venga restituito il puntatore. Usare sempre il Marshal.Release metodo per decrerere il conteggio dei riferimenti al termine del puntatore. È necessario rispettare le regole definite da COM quando si usano puntatori di interfaccia COM non elaborati.

GetComInterfaceForObject<T,TInterface>(T) è utile quando si chiama un metodo che espone un parametro dell'oggetto COM come IntPtr tipo o con il marshalling personalizzato. È anche possibile usare questo metodo in un oggetto gestito per ottenere un puntatore al wrapper COM chiamabile dell'oggetto, anche se questo è meno comune. Ad esempio, è possibile usare GetComInterfaceForObject<T,TInterface>(T) in un oggetto gestito esportato in COM per ottenere un puntatore dell'interfaccia per System.Runtime.InteropServices.UCOMIConnectionPointContainer.

L'overload del metodo consente la personalizzazione dell'interfaccia GetComInterfaceForObject<T,TInterface>(T) di query per impostazione predefinita. Per specificare se applicare la personalizzazione dell'interfaccia di query, usare l'overload del GetComInterfaceForObject(Object, Type, CustomQueryInterfaceMode) metodo.

Per altre informazioni, vedere gli articoli COM Callable Wrapper e Runtime Callable Wrapper.

Si applica a