Marshal.GetIUnknownForObjectInContext(Object) Método

Definição

Devolve uma interface IUnknown de um objeto gerido, se o chamador estiver no mesmo contexto que esse 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 IUnknown interface é solicitada.

Devoluções

IntPtr

nativeint

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

Atributos

Exemplos

O exemplo seguinte demonstra como recuperar uma IUnknown interface para um objeto gerido 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

Observações

Este método é o mesmo, GetIUnknownForObject exceto que retorna null se o chamador não estiver no mesmo contexto que o objeto.

Aplica-se a

Ver também