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 <xplatform.h>
6#include <stdio.h>
7
8
9BOOL boolManaged = true;
10BOOL boolNative = false;
11
12extern "C" DLL_EXPORT BOOL STDMETHODCALLTYPE Marshal_In(/*[in]*/BOOL boolValue)
13{
14 //Check the input
15 if(boolValue != boolManaged)
16 {
17 printf("Error in Function Marshal_In(Native Client)\n");
18
19 //Expected
20 printf("Expected: %s", (boolManaged)?"true":"false");
21
22 //Actual
23 printf("Actual: %s", (boolValue)?"true":"false");
24
25 //Return the error value instead if verification failed
26 return false;
27 }
28
29 return true;
30}
31
32extern "C" DLL_EXPORT BOOL STDMETHODCALLTYPE Marshal_InOut(/*[In,Out]*/BOOL boolValue)
33{
34 //Check the input
35 if(boolValue != boolManaged)
36 {
37 printf("Error in Function Marshal_InOut(Native Client)\n");
38
39 //Expected
40 printf("Expected: %s", (boolManaged)?"true":"false");
41
42 //Actual
43 printf("Actual: %s", (boolValue)?"true":"false");
44
45 //Return the error value instead if verification failed
46 return false;
47 }
48
49 //In-Place Change
50 boolValue = boolNative;
51
52 //Return
53 return true;
54}
55
56extern "C" DLL_EXPORT BOOL STDMETHODCALLTYPE Marshal_Out(/*[Out]*/BOOL boolValue)
57{
58 //In-Place Change
59 boolValue = boolNative;
60
61 //Return
62 return true;
63}
64
65extern "C" DLL_EXPORT BOOL STDMETHODCALLTYPE MarshalPointer_In(/*[in]*/BOOL *pboolValue)
66{
67 //Check the input
68 if(*pboolValue != boolManaged)
69 {
70 printf("Error in Function MarshalPointer_In(Native Client)\n");
71
72 //Expected
73 printf("Expected: %s", (boolManaged)?"true":"false");
74
75 //Actual
76 printf("Actual: %s", (*pboolValue)?"true":"false");
77
78 //Return the error value instead if verification failed
79 return false;
80 }
81
82 return true;
83}
84
85extern "C" DLL_EXPORT BOOL STDMETHODCALLTYPE MarshalPointer_InOut(/*[in,out]*/BOOL *pboolValue)
86{
87 //Check the input
88 if(*pboolValue != boolManaged)
89 {
90 printf("Error in Function MarshalPointer_InOut(Native Client)\n");
91
92 //Expected
93 printf("Expected: %s", (boolManaged)?"true":"false");
94
95 //Actual
96 printf("Actual: %s", (*pboolValue)?"true":"false");
97
98 //Return the error value instead if verification failed
99 return false;
100 }
101
102 //In-Place Change
103 *pboolValue = boolNative;
104
105 //Return
106 return true;
107}
108
109extern "C" DLL_EXPORT BOOL STDMETHODCALLTYPE MarshalPointer_Out(/*[out]*/ BOOL *pboolValue)
110{
111 //In-Place Change
112 *pboolValue = boolNative;
113
114 //Return
115 return true;
116}
117
118#pragma warning(push)
119#if _MSC_VER <= 1900
120// 'BOOL' forcing value to bool 'true' or 'false'
121#pragma warning(disable: 4800)
122#endif
123
124extern "C" DLL_EXPORT bool STDMETHODCALLTYPE Marshal_As_In(/*[in]*/bool boolValue)
125{
126 //Check the input
127 if(boolValue != (bool)boolManaged)
128 {
129 printf("Error in Function Marshal_As_In(Native Client)\n");
130
131 //Expected
132 printf("Expected: %s", (boolManaged)?"true":"false");
133
134 //Actual
135 printf("Actual: %s", (boolValue)?"true":"false");
136
137 //Return the error value instead if verification failed
138 return false;
139 }
140
141 return true;
142}
143
144extern "C" DLL_EXPORT bool STDMETHODCALLTYPE Marshal_As_InOut(/*[In,Out]*/bool boolValue)
145{
146 //Check the input
147 if(boolValue != (bool)boolManaged)
148 {
149 printf("Error in Function Marshal_As_InOut(Native Client)\n");
150
151 //Expected
152 printf("Expected: %s", (boolManaged)?"true":"false");
153
154 //Actual
155 printf("Actual: %s", (boolValue)?"true":"false");
156
157 //Return the error value instead if verification failed
158 return false;
159 }
160
161 //In-Place Change
162 boolValue = (bool)boolNative;
163
164 //Return
165 return true;
166}
167
168extern "C" DLL_EXPORT bool STDMETHODCALLTYPE Marshal_As_Out(/*[Out]*/bool boolValue)
169{
170 //In-Place Change
171 boolValue = (bool)boolNative;
172
173 //Return
174 return true;
175}
176
177#ifdef _WIN32
178extern "C" DLL_EXPORT bool STDMETHODCALLTYPE Marshal_ByValue_Variant(VARIANT_BOOL boolValue, bool expected)
179{
180 if (boolValue != (expected ? VARIANT_TRUE : VARIANT_FALSE))
181 {
182 printf("Error in function Marshal_ByValue_Variant(Native Client)\n");
183
184 printf("Expected %s ", expected ? "true" : "false");
185 printf("Actual %s (%hi)", boolValue == VARIANT_FALSE ? "false" : "(unknown variant value)", boolValue);
186
187 return false;
188 }
189
190 return true;
191}
192
193extern "C" DLL_EXPORT bool STDMETHODCALLTYPE Marshal_Ref_Variant(VARIANT_BOOL* pBoolValue)
194{
195 if (*pBoolValue != (boolManaged ? VARIANT_TRUE : VARIANT_FALSE))
196 {
197 printf("Error in function Marshal_ByValue_Variant(Native Client)\n");
198
199 printf("Expected %s ", boolManaged ? "true" : "false");
200 printf("Actual %s (%hi)", *pBoolValue == VARIANT_FALSE ? "false" : "(unknown variant value)", *pBoolValue);
201
202 return false;
203 }
204
205 *pBoolValue = (boolNative ? VARIANT_TRUE : VARIANT_FALSE);
206 return true;
207}
208
209struct ContainsVariantBool
210{
211 VARIANT_BOOL value;
212};
213
214extern "C" DLL_EXPORT bool STDMETHODCALLTYPE Marshal_ByValue_Struct_Variant(ContainsVariantBool value, bool expected)
215{
216 if (value.value != (expected ? VARIANT_TRUE : VARIANT_FALSE))
217 {
218 printf("Error in function Marshal_ByValue_Variant(Native Client)\n");
219
220 printf("Expected %s ", expected ? "true" : "false");
221 printf("Actual %s (%hi)", value.value == VARIANT_FALSE ? "false" : "(unknown variant value)", value.value);
222
223 return false;
224 }
225
226 return true;
227}
228
229extern "C" DLL_EXPORT bool STDMETHODCALLTYPE Marshal_Ref_Struct_Variant(ContainsVariantBool* pBoolValue)
230{
231 if (pBoolValue->value != (boolManaged ? VARIANT_TRUE : VARIANT_FALSE))
232 {
233 printf("Error in function Marshal_ByValue_Variant(Native Client)\n");
234
235 printf("Expected %s ", boolManaged ? "true" : "false");
236 printf("Actual %s (%hi)", pBoolValue->value == VARIANT_FALSE ? "false" : "(unknown variant value)", pBoolValue->value);
237
238 return false;
239 }
240
241 pBoolValue->value = (boolNative ? VARIANT_TRUE : VARIANT_FALSE);
242 return true;
243}
244
245#endif
246#pragma warning(pop)
247