-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathTest_NativeExport.cs
More file actions
32 lines (28 loc) · 985 Bytes
/
Test_NativeExport.cs
File metadata and controls
32 lines (28 loc) · 985 Bytes
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
using System;
using System.Runtime.InteropServices;
using GCore.NativeInterop;
using LibNamespace;
namespace LibNamespace
{
public static class Test_NativeExport
{
// begin-snippet: Test_NativeExport_CS
public delegate int FunctionPointerCallbackDelegate(int a);
[UnmanagedCallersOnly]
public static int Test_NativeExport_Call(IntPtr moduleHandle, int number)
{
var exportedDelegate = ModuleLoader.GetExport<FunctionPointerCallbackDelegate>(moduleHandle, "Test_NativeExport_ExternC");
int result = exportedDelegate(number);
unsafe
{
unchecked
{
var callbackFuncPtr = (delegate* unmanaged[Cdecl]<int, int>)ModuleLoader.GetExport(moduleHandle, "Test_NativeExport_ExternC");
result += callbackFuncPtr(number);
}
}
return result / 2;
}
// end-snippet
}
}