1 | // Licensed to the .NET Foundation under one or more agreements. |
2 | // The .NET Foundation licenses this file to you under the MIT license. |
3 | // See the LICENSE file in the project root for more information. |
4 | |
5 | #include <stdio.h> |
6 | #include <xplatform.h> |
7 | |
8 | const int intManaged = 1000; |
9 | const int intNative = 2000; |
10 | const int intReturn = 3000; |
11 | const int intErrReturn = 4000; |
12 | const int expectedStackGuard = 5000; |
13 | |
14 | extern "C" DLL_EXPORT int STDMETHODCALLTYPE MarshalPointer_In(/*[in]*/int *pintValue, int stackGuard) |
15 | { |
16 | if (*pintValue != intManaged) |
17 | { |
18 | printf("Error in Function MarshalPointer_In(Native Client)\n" ); |
19 | printf("Expected:%u\n" , intManaged); |
20 | printf("Actual:%u\n" ,*pintValue); |
21 | |
22 | // Return the error value instead if verification failed |
23 | return intErrReturn; |
24 | } |
25 | if (stackGuard != expectedStackGuard) |
26 | { |
27 | printf("Stack error in Function MarshalPointer_In(Native Client)\n" ); |
28 | return intErrReturn; |
29 | } |
30 | |
31 | return intReturn; |
32 | } |
33 | |
34 | extern "C" DLL_EXPORT int STDMETHODCALLTYPE MarshalPointer_InOut(/*[in,out]*/int *pintValue, int stackGuard) |
35 | { |
36 | if(*pintValue != intManaged) |
37 | { |
38 | printf("Error in Function MarshalPointer_InOut(Native Client)\n" ); |
39 | printf("Expected:%u\n" , intManaged); |
40 | printf("Actual:%u\n" ,*pintValue); |
41 | |
42 | // Return the error value instead if verification failed |
43 | return intErrReturn; |
44 | } |
45 | if (stackGuard != expectedStackGuard) |
46 | { |
47 | printf("Stack error in Function MarshalPointer_In(Native Client)\n" ); |
48 | return intErrReturn; |
49 | } |
50 | |
51 | // In-Place Change |
52 | *pintValue = intNative; |
53 | |
54 | return intReturn; |
55 | } |
56 | |
57 | extern "C" DLL_EXPORT int STDMETHODCALLTYPE MarshalPointer_Out(/*[out]*/ int *pintValue, int stackGuard) |
58 | { |
59 | *pintValue = intNative; |
60 | if (stackGuard != expectedStackGuard) |
61 | { |
62 | printf("Stack error in Function MarshalPointer_In(Native Client)\n" ); |
63 | return intErrReturn; |
64 | } |
65 | |
66 | return intReturn; |
67 | } |
68 | |
69 | typedef void (*GCCallback)(void); |
70 | extern "C" DLL_EXPORT int STDMETHODCALLTYPE TestNoGC(int *pintValue, GCCallback gcCallback) |
71 | { |
72 | int origValue = *pintValue; |
73 | gcCallback(); |
74 | int afterGCValue = *pintValue; |
75 | if (origValue != afterGCValue) |
76 | { |
77 | printf("Error in Function TestNoGC(Native Client)\n" ); |
78 | printf("Expected:%u\n" , origValue); |
79 | printf("Actual:%u\n" , afterGCValue); |
80 | return intErrReturn; |
81 | } |
82 | |
83 | return intReturn; |
84 | } |
85 | |
86 | |