Marshal.GetIUnknownForObjectInContext(Object) Método

Definição

Retornará uma interface IUnknown de um objeto gerenciado se o chamador estiver no mesmo contexto que o objeto.

public:
 static IntPtr GetIUnknownForObjectInContext(System::Object ^ o);
public static IntPtr GetIUnknownForObjectInContext (object o);
[System.Security.SecurityCritical]
public static IntPtr GetIUnknownForObjectInContext (object o);
static member GetIUnknownForObjectInContext : obj -> nativeint
[<System.Security.SecurityCritical>]
static member GetIUnknownForObjectInContext : obj -> nativeint
Public Shared Function GetIUnknownForObjectInContext (o As Object) As IntPtr

Parâmetros

o
Object

O objeto cuja interface IUnknown é solicitada.

Retornos

IntPtr

nativeint

A interface IUnknown para o objeto especificado ou null, se o chamador não estiver no mesmo contexto que o objeto especificado.

Atributos

Exemplos

O exemplo a seguir demonstra como recuperar uma IUnknown interface para um objeto gerenciado usando o GetIUnknownForObjectInContext método.

using System;
using System.Runtime.InteropServices;

class Program
{

    static void Run()
    {

        // Create an int object
        int obj = 1;

        Console.WriteLine("Calling Marshal.GetIUnknownForObjectInContext...");

        // Get the IUnKnown pointer for the Integer object
        IntPtr pointer = Marshal.GetIUnknownForObjectInContext(obj);

        Console.WriteLine("Calling Marshal.Release...");

        // Always call Marshal.Release to decrement the reference count.
        Marshal.Release(pointer);
    }

    static void Main(string[] args)
    {
        Run();
    }
}
Imports System.Runtime.InteropServices

Module Program


    Sub Run()

        ' Dim an Integer object
        Dim IntegerObject As Integer = 1

        ' Dim a pointer
        Dim pointer As IntPtr

        Console.WriteLine("Calling Marshal.GetIUnknownForObjectInContext...")

        ' Get the IUnKnown pointer for the Integer object
        pointer = Marshal.GetIUnknownForObjectInContext(IntegerObject)

        Console.WriteLine("Calling Marshal.Release...")

        ' Always call Marshal.Release to decrement the reference count.
        Marshal.Release(pointer)



    End Sub

    Sub Main(ByVal args() As String)

        Run()

    End Sub

End Module

Comentários

Esse método é o mesmo GetIUnknownForObject que ele retorna null se o chamador não estiver no mesmo contexto que o objeto.

Aplica-se a

Confira também