-
Notifications
You must be signed in to change notification settings - Fork 4.6k
/
FuncPtrAsDelegateParamManaged.cs
45 lines (38 loc) · 1.25 KB
/
FuncPtrAsDelegateParamManaged.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
37
38
39
40
41
42
43
44
45
using System;
using System.Text;
using System.Security;
using System.Runtime.InteropServices;
using TestLibrary;
//Value Pass N-->M M--->N
//Cdecl -1 678
public class Test_FuncPtrAsDelegateParamManaged
{
//TestMethod1
[DllImport("FuncPtrAsDelegateParamNative", CallingConvention = CallingConvention.Cdecl)]
public static extern bool DoCallBack_Cdecl(Cdeclcaller caller);
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
public delegate int CdeFunc();
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
public delegate int Cdeclcaller(CdeFunc func);
[SecuritySafeCritical]
private static int TestMethod_ReversePInvoke_Cdecl(CdeFunc func)
{
if (-1 != func())
{
TestFramework.LogError("01","The Return Value(TestMethod_ReversePInvoke_Cdecl) is wrong");
}
return 678;
}
[SecuritySafeCritical]
static int Main()
{
bool breturn = true;
TestFramework.BeginScenario("ReversePInvoke Cdecl");
if (!DoCallBack_Cdecl(new Cdeclcaller(TestMethod_ReversePInvoke_Cdecl)))
{
breturn = false;
TestFramework.LogError("04","The Return value(DoCallBack_Cdecl) is wrong");
}
return breturn ? 100: 101;
}
}