Compartilhar via


Método Marshal.QueryInterface (IntPtr, Guid, IntPtr)

 

Dica

The .NET API Reference documentation has a new home. Visit the .NET API Browser on docs.microsoft.com to see the new experience.

Solicita um ponteiro para uma interface especificada de um objeto COM.

Namespace:   System.Runtime.InteropServices
Assembly:  mscorlib (em mscorlib.dll)

Sintaxe

[SecurityCriticalAttribute]
public static int QueryInterface(
    IntPtr pUnk,
    ref Guid iid,
    out IntPtr ppv
)
public:
[SecurityCriticalAttribute]
static int QueryInterface(
    IntPtr pUnk,
    Guid% iid,
    [OutAttribute] IntPtr% ppv
)
[<SecurityCriticalAttribute>]
static member QueryInterface : 
        pUnk:nativeint *
        iid:Guid byref *
        ppv:nativeint byref -> int
<SecurityCriticalAttribute>
Public Shared Function QueryInterface (
    pUnk As IntPtr,
    ByRef iid As Guid,
    <OutAttribute> ByRef ppv As IntPtr
) As Integer

Parâmetros

  • iid
    Type: System.Guid

    O IID (identificador de interface) da interface solicitada.

  • ppv
    Type: System.IntPtr

    Quando este método retorna, ele contém uma referência à interface retornada.

Valor Retornado

Type: System.Int32

Um HRESULT que indica o êxito ou falha da chamada.

Comentários

O QueryInterface método expõe o IUnknown::QueryInterface método de um objeto COM, que tenta obter um ponteiro de interface específica. Usando QueryInterface em uma COM o objeto é o mesmo que executar uma operação de conversão em código gerenciado. Chamando um objeto com esse método faz com que a contagem de referência incrementar o ponteiro de interface antes do ponteiro será retornado. Sempre use Marshal.Release para diminuir a contagem de referência quando tiver concluído com o ponteiro. Para obter um IntPtr valor que representa um IUnknown ponteiro de interface, você pode chamar Marshal.GetComInterfaceForObject, Marshal.GetIUnknownForObject, ou Marshal.GetIDispatchForObject.

Segurança

SecurityCriticalAttribute

requires full trust for the immediate caller. This member cannot be used by partially trusted or transparent code.

Informações de Versão

Plataforma Universal do Windows
Disponível desde 8
.NET Framework
Disponível desde 1.1
Biblioteca de Classes Portátil
Com suporte no: plataformas portáteis do .NET
Windows Phone Silverlight
Disponível desde 8.0
Windows Phone
Disponível desde 8.1

Confira Também

AddRef
Release
GetComInterfaceForObject
GetIUnknownForObject
GetIDispatchForObject
GetObjectForIUnknown
Classe Marshal
Namespace System.Runtime.InteropServices

Retornar ao início