Compartilhar via


Método Marshal.GetIUnknownForObjectInContext (Object)

 

Dica

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

Retorna um IUnknown de interface de um objeto gerenciado, se o chamador estiver no mesmo contexto de objeto.

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

Sintaxe

[SecurityCriticalAttribute]
public static IntPtr GetIUnknownForObjectInContext(
    object o
)
public:
[SecurityCriticalAttribute]
static IntPtr GetIUnknownForObjectInContext(
    Object^ o
)
[<SecurityCriticalAttribute>]
static member GetIUnknownForObjectInContext : 
        o:Object -> nativeint
<SecurityCriticalAttribute>
Public Shared Function GetIUnknownForObjectInContext (
    o As Object
) As IntPtr

Parâmetros

  • o
    Type: System.Object

    O objeto cuja interface IUnknown é solicitada.

Valor Retornado

Type: System.IntPtr

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

Comentários

Esse método é o mesmo que GetIUnknownForObject exceto que ela retorna null se o chamador não está no mesmo contexto de objeto.

Exemplos

O exemplo a seguir demonstra como recuperar um 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

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

.NET Framework
Disponível desde 2.0

Confira Também

GetIUnknownForObject
Release
GetObjectForIUnknown
Classe Marshal
Namespace System.Runtime.InteropServices

Retornar ao início