-
Notifications
You must be signed in to change notification settings - Fork 4
/
Test_NativeFunctionPointer.h
57 lines (42 loc) · 1.49 KB
/
Test_NativeFunctionPointer.h
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#pragma once
#include "Common.h"
namespace Test_NativeFunctionPointer
{
// begin-snippet: Test_NativeFunctionPointer_CallbackFunc_CPP
int FEXPORT CallbackFunc(int i)
{
return i * 2;
}
// end-snippet
bool Run(dotnet_runtime::Library& a_lib)
{
bool ret = true;
typedef int (CORECLR_DELEGATE_CALLTYPE* custom_entry_point_fn)(void*, int);
// begin-snippet: Test_NativeFunctionPointer_CallbackPointer_CPP
void* fpNativeCallback = (void*)&CallbackFunc;
// end-snippet
{ // checked function pointer to delegate
// begin-snippet: Test_NativeFunctionPointer_CallbackFunc_Checked_CPP
auto fpTest_NativeFunctionPointer_Checked = (custom_entry_point_fn)a_lib.GetCustomEntrypoint(
STR("LibNamespace.Test_NativeFunctionPointer"),
STR("Test_NativeFunctionPointer_Checked")
);
bool success = fpTest_NativeFunctionPointer_Checked(fpNativeCallback, 4) == 8;
LogTest(success, L"Test_NativeFunctionPointer_Checked");
// end-snippet
ret &= success;
}
{ // unchecked function pointer call
// begin-snippet: Test_NativeFunctionPointer_CallbackFunc_Unchecked_CPP
auto fpTest_NativeFunctionPointer_Unchecked = (custom_entry_point_fn)a_lib.GetCustomEntrypoint(
STR("LibNamespace.Test_NativeFunctionPointer"),
STR("Test_NativeFunctionPointer_Unchecked")
);
bool success = fpTest_NativeFunctionPointer_Unchecked(fpNativeCallback, 4) == 8;
LogTest(success, L"Test_NativeFunctionPointer_Unchecked");
// end-snippet
ret &= success;
}
return ret;
}
}