Marshal.GetIUnknownForObject(Object) 메서드
정의
public:
static IntPtr GetIUnknownForObject(System::Object ^ o);
[System.Security.SecurityCritical]
public static IntPtr GetIUnknownForObject (object o);
[System.Runtime.Versioning.SupportedOSPlatform("windows")]
public static IntPtr GetIUnknownForObject (object o);
public static IntPtr GetIUnknownForObject (object o);
[<System.Security.SecurityCritical>]
static member GetIUnknownForObject : obj -> nativeint
[<System.Runtime.Versioning.SupportedOSPlatform("windows")>]
static member GetIUnknownForObject : obj -> nativeint
static member GetIUnknownForObject : obj -> nativeint
Public Shared Function GetIUnknownForObject (o As Object) As IntPtr
매개 변수
- o
- Object
IUnknown
인터페이스가 요청되는 개체입니다.The object whose IUnknown
interface is requested.
반환
o
매개 변수에 대한 IUnknown
포인터입니다.The IUnknown
pointer for the o
parameter.
- 특성
예제
다음 예제에서는 메서드를 사용 하 여 관리 되는 개체에 대 한 IUnknown 인터페이스를 검색 하는 방법을 보여 줍니다 GetIUnknownForObject .The following example demonstrates how to retrieve an IUnknown interface for a managed object using the GetIUnknownForObject method.
using System;
using System.Runtime.InteropServices;
class Program
{
static void Run()
{
// Create an int object
int obj = 1;
Console.WriteLine("Calling Marshal.GetIUnknownForObject...");
// Get the IUnKnown pointer for the Integer object
IntPtr pointer = Marshal.GetIUnknownForObject(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.GetIUnknownForObject...")
' Get the IUnKnown pointer for the Integer object
pointer = Marshal.GetIUnknownForObject(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
설명
관리 코드에서 인터페이스를 사용 하 여 직접 작업 하는 경우는 거의 IUnknown
없습니다.In managed code, you seldom work directly with the IUnknown
interface. 그러나 GetIUnknownForObject 는 COM 개체 매개 변수를 형식으로 노출 하는 메서드를 호출 IntPtr 하거나 사용자 지정 마샬링을 사용 하는 경우에 유용 합니다.However, GetIUnknownForObject is useful when calling a method that exposes a COM object parameter as an IntPtr type, or with custom marshaling. 이 메서드를 사용 하 여 개체를 호출 하면 포인터를 반환 하기 전에 인터페이스 포인터에서 참조 횟수가 증가 합니다.Calling an object with this method causes the reference count to increment on the interface pointer before the pointer is returned. 포인터를 사용 하 Marshal.Release 여 완료 한 후에는 항상를 사용 하 여 참조 횟수를 감소 시킵니다.Always use Marshal.Release to decrement the reference count once you have finished with the pointer. 이 메서드는 메서드의 반대 기능을 제공 합니다 Marshal.GetObjectForIUnknown .This method provides the opposite functionality of the Marshal.GetObjectForIUnknown method.
관리 되는 개체에 대해이 메서드를 사용 하 여 개체에 대 한 COM 호출 가능 래퍼 에 대 한 인터페이스 포인터를 가져올 수도 있습니다.You can also use this method on a managed object to obtain an interface pointer to the COM Callable Wrapper for the object.