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

属性

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

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

適用対象

こちらもご覧ください