Marshal.GetIUnknownForObjectInContext(Object) メソッド

定義

呼び出し元がそのオブジェクトと同じコンテキストにある場合は、マネージド オブジェクトから IUnknown インターフェイスを返します。

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

パラメーター

o
Object

IUnknown インターフェイスが要求されるオブジェクト。

返品

IntPtr

nativeint

指定したオブジェクトの IUnknown ポインター。呼び出し元が指定したオブジェクトと同じコンテキストにない場合に null します。

属性

次の例では、GetIUnknownForObjectInContext メソッドを使用してマネージド オブジェクトのIUnknown インターフェイスを取得する方法を示します。

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

注釈

このメソッドは、呼び出し元がオブジェクトと同じコンテキストにない場合にnullを返す点を除き、GetIUnknownForObjectと同じです。

適用対象

こちらもご覧ください