-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathTest_NativeFunctionPointer.cs
36 lines (33 loc) · 1.15 KB
/
Test_NativeFunctionPointer.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
using System;
using System.Runtime.InteropServices;
namespace LibNamespace
{
public static class Test_NativeFunctionPointer
{
#region Test_NativeFunctionPointer_Checked_CS
public delegate int FunctionPointerCallbackDelegate(int a);
[UnmanagedCallersOnly]
public static int Test_NativeFunctionPointer_Checked(IntPtr nativeFunctionPtr, int number)
{
var callbackFuncDelegate =
(FunctionPointerCallbackDelegate)Marshal.GetDelegateForFunctionPointer(nativeFunctionPtr,
typeof(FunctionPointerCallbackDelegate));
return callbackFuncDelegate(number);
}
#endregion
#region Test_NativeFunctionPointer_Unchecked_CS
[UnmanagedCallersOnly]
public static int Test_NativeFunctionPointer_Unchecked(IntPtr nativeFunctionPtr, int number)
{
unsafe
{
unchecked
{
var callbackFuncPtr = (delegate* unmanaged[Cdecl]<int, int>)nativeFunctionPtr;
return callbackFuncPtr(number);
}
}
}
#endregion
}
}