Marshal.GetIUnknownForObjectInContext(Object) Metoda

Definice

Vrátí IUnknown rozhraní ze spravovaného objektu, pokud je volající ve stejném kontextu jako tento objekt.

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

Parametry

o
Object

Objekt, jehož IUnknown rozhraní je požadováno.

Návraty

IntPtr

nativeint

Ukazatel IUnknown pro zadaný objekt nebo null pokud volající není ve stejném kontextu jako zadaný objekt.

Atributy

Příklady

Následující příklad ukazuje, jak načíst IUnknown rozhraní pro spravovaný objekt pomocí GetIUnknownForObjectInContext metody .

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

Poznámky

Tato metoda je stejná, s GetIUnknownForObject výjimkou toho, že vrátí null , pokud volající není ve stejném kontextu jako objekt.

Platí pro

Viz také