Nota: este método es nuevo en la versión 2.0 de .NET Framework.
Devuelve una interfaz
IUnknown de un objeto administrado, si el llamador está en el mismo contexto que ese objeto.
Espacio de nombres: System.Runtime.InteropServices
Ensamblado: mscorlib (en mscorlib.dll)

Sintaxis
Visual Basic (Declaración)
Public Shared Function GetIUnknownForObjectInContext ( _
o As Object _
) As IntPtr
Dim o As Object
Dim returnValue As IntPtr
returnValue = Marshal.GetIUnknownForObjectInContext(o)
public static IntPtr GetIUnknownForObjectInContext (
Object o
)
public:
static IntPtr GetIUnknownForObjectInContext (
Object^ o
)
public static IntPtr GetIUnknownForObjectInContext (
Object o
)
public static function GetIUnknownForObjectInContext (
o : Object
) : IntPtr
Parámetros
- o
Objeto cuya interfaz IUnknown se solicita.
Valor devuelto
El puntero
IUnknown para el parámetro
o o referencia de objeto null (
Nothing en Visual Basic) si el llamador no está en el mismo contexto que el objeto especificado.

Comentarios
Este método es igual que GetIUnknownForObject con la diferencia de que devuelve referencia de objeto null (Nothing en Visual Basic) si el llamador no está en el mismo contexto que el objeto.

Ejemplo
En el ejemplo de código siguiente se muestra cómo recuperar una interfaz IUnknown para un objeto administrado utilizando el método GetIUnknownForObjectInContext.
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
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();
}
}

Seguridad de .NET Framework

Plataformas
Windows 98, Windows 2000 SP4, Windows Millennium, Windows Server 2003, Windows XP Media Center, Windows XP Professional x64, Windows XP SP2, Windows XP Starter Edition
.NET Framework no admite todas las versiones de cada plataforma. Para obtener una lista de las versiones admitidas, vea Requisitos del sistema.

Información de versión
.NET Framework
Compatible con: 2.0

Vea también