다음을 통해 공유


Marshal.GetFunctionPointerForDelegate 메서드

정의

오버로드

Name Description
GetFunctionPointerForDelegate(Delegate)
사용되지 않음.

대리자를 관리되지 않는 코드에서 호출할 수 있는 함수 포인터로 변환합니다.

GetFunctionPointerForDelegate<TDelegate>(TDelegate)

지정된 형식의 대리자를 관리되지 않는 코드에서 호출할 수 있는 함수 포인터로 변환합니다.

GetFunctionPointerForDelegate(Delegate)

Source:
Marshal.cs
Source:
Marshal.cs
Source:
Marshal.cs
Source:
Marshal.cs
Source:
Marshal.cs

주의

GetFunctionPointerForDelegate(Delegate) may be unavailable in future releases. Instead, use GetFunctionPointerForDelegate<T>(T). For more info, go to http://go.microsoft.com/fwlink/?LinkID=296522

대리자를 관리되지 않는 코드에서 호출할 수 있는 함수 포인터로 변환합니다.

public:
 static IntPtr GetFunctionPointerForDelegate(Delegate ^ d);
[System.Obsolete("GetFunctionPointerForDelegate(Delegate) may be unavailable in future releases. Instead, use GetFunctionPointerForDelegate<T>(T). For more info, go to http://go.microsoft.com/fwlink/?LinkID=296522")]
[System.Security.SecurityCritical]
public static IntPtr GetFunctionPointerForDelegate(Delegate d);
[System.Diagnostics.CodeAnalysis.RequiresDynamicCode("Marshalling code for the delegate might not be available. Use the GetFunctionPointerForDelegate<TDelegate> overload instead.")]
public static IntPtr GetFunctionPointerForDelegate(Delegate d);
public static IntPtr GetFunctionPointerForDelegate(Delegate d);
[System.Security.SecurityCritical]
public static IntPtr GetFunctionPointerForDelegate(Delegate d);
[<System.Obsolete("GetFunctionPointerForDelegate(Delegate) may be unavailable in future releases. Instead, use GetFunctionPointerForDelegate<T>(T). For more info, go to http://go.microsoft.com/fwlink/?LinkID=296522")>]
[<System.Security.SecurityCritical>]
static member GetFunctionPointerForDelegate : Delegate -> nativeint
[<System.Diagnostics.CodeAnalysis.RequiresDynamicCode("Marshalling code for the delegate might not be available. Use the GetFunctionPointerForDelegate<TDelegate> overload instead.")>]
static member GetFunctionPointerForDelegate : Delegate -> nativeint
static member GetFunctionPointerForDelegate : Delegate -> nativeint
[<System.Security.SecurityCritical>]
static member GetFunctionPointerForDelegate : Delegate -> nativeint
Public Shared Function GetFunctionPointerForDelegate (d As Delegate) As IntPtr

매개 변수

d
Delegate

관리되지 않는 코드에 전달할 대리자입니다.

반환

IntPtr

nativeint

관리되지 않는 코드에 전달할 수 있는 값이며, 이를 사용하여 기본 관리되는 대리자를 호출할 수 있습니다.

특성

예외

매개 변수는 제네릭 형식 정의입니다.

매개 변수는 .입니다 .

동적 진입점 할당은 현재 환경에서 지원되지 않습니다.

설명

대리 자는 기본 플랫폼 호출 규칙을 사용하여 관리되지 않는 코드에 전달할 수 있는 함수 포인터로 변환됩니다. 대리자를 적용하여 호출 규칙을 설정할 수 있습니다.

관리 코드에서 가비지 수집기에서 대리자를 수동으로 수집하지 않도록 해야 합니다. 가비지 수집기는 관리되지 않는 코드에 대한 참조를 추적하지 않습니다. 기본 호출이 완료되기 전에 대리자가 수집되지 않도록 하는 데 사용합니다 .

var callback = new MyNativeCallback(MyManagedMethod);
IntPtr fnPtr = Marshal.GetFunctionPointerForDelegate(callback);
NativeMethod(fnPtr);
GC.KeepAlive(callback); // Prevent collection — fnPtr does not root the delegate.

대리자를 마샬링하는 P/Invoke는 사용자를 대신하여 처리합니다 .

var callback = new MyNativeCallback(MyManagedMethod);
NativeMethod(callback); // P/Invoke marshals the delegate and keeps it alive for the duration of the call.

네이티브 코드가 호출 기간 이후 함수 포인터를 저장하는 경우 전체 수명(예: 필드에 저장)에 대한 대리자를 루트로 지정합니다.

이 API는 Windows , SELinux의 및 WebAssembly와 같은 동적 진입점 할당을 지원하지 않는 환경에서 지원되지 않습니다.

대신 함수 포인터를 사용하는 것이 좋습니다. 함수 포인터는 더 효율적이고, 올바르게 사용하기 쉽고, 모든 환경에서 지원됩니다.

적용 대상

GetFunctionPointerForDelegate<TDelegate>(TDelegate)

Source:
Marshal.cs
Source:
Marshal.cs
Source:
Marshal.cs
Source:
Marshal.cs
Source:
Marshal.cs

지정된 형식의 대리자를 관리되지 않는 코드에서 호출할 수 있는 함수 포인터로 변환합니다.

public:
generic <typename TDelegate>
 static IntPtr GetFunctionPointerForDelegate(TDelegate d);
[System.Security.SecurityCritical]
public static IntPtr GetFunctionPointerForDelegate<TDelegate>(TDelegate d);
public static IntPtr GetFunctionPointerForDelegate<TDelegate>(TDelegate d);
[<System.Security.SecurityCritical>]
static member GetFunctionPointerForDelegate : 'Delegate -> nativeint
static member GetFunctionPointerForDelegate : 'Delegate -> nativeint
Public Shared Function GetFunctionPointerForDelegate(Of TDelegate) (d As TDelegate) As IntPtr

형식 매개 변수

TDelegate

변환할 대리자의 형식입니다.

매개 변수

d
TDelegate

관리되지 않는 코드에 전달할 대리자입니다.

반환

IntPtr

nativeint

관리되지 않는 코드에 전달할 수 있는 값이며, 이를 사용하여 기본 관리되는 대리자를 호출할 수 있습니다.

특성

예외

매개 변수는 제네릭 형식 정의입니다.

매개 변수는 .입니다 .

동적 진입점 할당은 현재 환경에서 지원되지 않습니다.

설명

대리 자는 기본 플랫폼 호출 규칙을 사용하여 관리되지 않는 코드에 전달할 수 있는 함수 포인터로 변환됩니다. 대리자를 적용하여 호출 규칙을 설정할 수 있습니다.

관리 코드에서 가비지 수집기에서 대리자를 수동으로 수집하지 않도록 해야 합니다. 가비지 수집기는 관리되지 않는 코드에 대한 참조를 추적하지 않습니다. 기본 호출이 완료되기 전에 대리자가 수집되지 않도록 하는 데 사용합니다 .

var callback = new MyNativeCallback(MyManagedMethod);
IntPtr fnPtr = Marshal.GetFunctionPointerForDelegate(callback);
NativeMethod(fnPtr);
GC.KeepAlive(callback); // Prevent collection — fnPtr does not root the delegate.

대리자를 마샬링하는 P/Invoke는 사용자를 대신하여 처리합니다 .

var callback = new MyNativeCallback(MyManagedMethod);
NativeMethod(callback); // P/Invoke marshals the delegate and keeps it alive for the duration of the call.

네이티브 코드가 호출 기간 이후 함수 포인터를 저장하는 경우 전체 수명(예: 필드에 저장)에 대한 대리자를 루트로 지정합니다.

이 API는 Windows , SELinux의 및 WebAssembly와 같은 동적 진입점 할당을 지원하지 않는 환경에서 지원되지 않습니다.

대신 함수 포인터를 사용하는 것이 좋습니다. 함수 포인터는 더 효율적이고, 올바르게 사용하기 쉽고, 모든 환경에서 지원됩니다.

적용 대상