Marshal.GetIUnknownForObjectInContext(Object) 方法
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
從 Managed 物件傳回 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
Managed 物件的 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
備註
這個方法與 相同 GetIUnknownForObject ,不同之處在於,如果呼叫端不在與 物件相同的內容中,則會傳回 null
此方法。