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
7struct test1 {
8 LONG64 a;
9 LONG64 b;
10};
11
12extern "C" DLL_EXPORT LONG64 STDMETHODCALLTYPE PassLayout(test1* i) {
13 printf("PassLayout: i->a = %lld\n", i->a);
14 printf("PassLayout: i->b = %lld\n", i->b);
15 return i->b;
16}
17
18
19struct AsAnyField
20{
21 int * intArray;
22};
23
24
25extern "C" DLL_EXPORT BOOL STDMETHODCALLTYPE PassUnicodeStr(LPCWSTR str)
26{
27 return (SHORT)str[0] == 0x0030 && (SHORT)str[1] == 0x7777 && (SHORT)str[2] == 0x000A;
28}
29extern "C" DLL_EXPORT BOOL STDMETHODCALLTYPE PassAnsiStr(LPCSTR str , BOOL isIncludeUnMappableChar)
30{
31 if(isIncludeUnMappableChar)
32 return (BYTE)str[0] == 0x30 && (BYTE)str[1] == 0x3f && (BYTE)str[2] == 0x0A;
33 else
34 return (BYTE)str[0] == 0x30 && (BYTE)str[1] == 0x35 && (BYTE)str[2] == 0x0A;
35}
36
37extern "C" DLL_EXPORT BOOL STDMETHODCALLTYPE PassUnicodeStrbd(LPCWSTR str)
38{
39 return (SHORT)str[0] == 0x0030 && (SHORT)str[1] == 0x7777 && (SHORT)str[2] == 0x000A;
40}
41extern "C" DLL_EXPORT BOOL STDMETHODCALLTYPE PassAnsiStrbd(LPCSTR str , BOOL isIncludeUnMappableChar)
42{
43 if(isIncludeUnMappableChar)
44 return (BYTE)str[0] == 0x30 && (BYTE)str[1] == 0x3f && (BYTE)str[2] == 0x0A;
45 else
46 return (BYTE)str[0] == 0x30 && (BYTE)str[1] == 0x35 && (BYTE)str[2] == 0x0A;
47}
48
49extern "C" DLL_EXPORT BOOL STDMETHODCALLTYPE PassUnicodeCharArray(WCHAR CharArray_In [], WCHAR CharArray_InOut [], WCHAR CharArray_Out [])
50{
51 BOOL ret = FALSE;
52 ret = (SHORT)CharArray_In[0] == 0x0030 && (SHORT)CharArray_In[1] == 0x7777 && (SHORT)CharArray_In[2] == 0x000A
53 && (SHORT)CharArray_InOut[0] == 0x0030 && (SHORT)CharArray_InOut[1] == 0x7777 && (SHORT)CharArray_InOut[2] == 0x000A ;
54
55 // revese the string for passing back
56 WCHAR temp = CharArray_InOut[0];
57
58 CharArray_InOut[0] = CharArray_InOut[2];
59 CharArray_Out[0] = CharArray_InOut[2];
60 CharArray_Out[1] = CharArray_InOut[1];
61 CharArray_InOut[2] = temp;
62 CharArray_Out[2] = temp;
63 return ret;
64}
65extern "C" DLL_EXPORT BOOL STDMETHODCALLTYPE PassAnsiCharArray(CHAR CharArray_In [], CHAR CharArray_InOut [], CHAR CharArray_Out [] ,
66 BOOL isIncludeUnMappableChar)
67{
68 BOOL ret = FALSE;
69 if(isIncludeUnMappableChar)
70 ret = (BYTE)CharArray_In[0] == 0x30 && (BYTE)CharArray_In[1] == 0x3f && (BYTE)CharArray_In[2] == 0x0A
71 && (BYTE)CharArray_InOut[0] == 0x30 && (BYTE)CharArray_InOut[1] == 0x3f && (BYTE)CharArray_InOut[2] == 0x0A;
72 else
73 ret = (BYTE)CharArray_In[0] == 0x30 && (BYTE)CharArray_In[1] == 0x35 && (BYTE)CharArray_In[2] == 0x0A
74 && (BYTE)CharArray_InOut[0] == 0x30 && (BYTE)CharArray_InOut[1] == 0x35 && (BYTE)CharArray_InOut[2] == 0x0A;
75
76 // reverse the string for passing back
77 CHAR temp = CharArray_InOut[0];
78
79 CharArray_InOut[0] = CharArray_InOut[2];
80 CharArray_Out[0] = CharArray_InOut[2];
81 CharArray_Out[1] = CharArray_InOut[1];
82 CharArray_InOut[2] = temp;
83 CharArray_Out[2] = temp;
84
85 return ret;
86}
87
88extern "C" DLL_EXPORT BOOL STDMETHODCALLTYPE PassArraySbyte(
89 BYTE sbyteArray[], BYTE sbyteArray_In[], BYTE sbyteArray_InOut[], BYTE sbyteArray_Out[], BYTE expected[], int len){
90
91 for(int i = 0; i < len; i++)
92 {
93 if(sbyteArray[i] != expected[i] || sbyteArray_In[i] != expected[i] || sbyteArray_InOut[i] != expected[i])
94 {
95 printf("Not correct pass in paremeter in PassArraySbyte\n");
96 return FALSE;
97 }
98 sbyteArray_InOut[i] = 10 + expected[i];
99 sbyteArray_Out[i] = 10 + expected[i];
100 }
101 return TRUE;
102}
103
104
105extern "C" DLL_EXPORT BOOL STDMETHODCALLTYPE PassArrayByte(
106 BYTE byteArray[], BYTE byteArray_In[], BYTE byteArray_InOut[], BYTE byteArray_Out[], BYTE expected[], int len){
107
108 for(int i = 0; i < len; i++)
109 {
110 if(byteArray[i] != expected[i] || byteArray_In[i] != expected[i] || byteArray_InOut[i] != expected[i])
111 {
112 printf("Not correct pass in paremeter in PassArrayByte\n");
113 return FALSE;
114 }
115 byteArray_InOut[i] = 10 + expected[i];
116 byteArray_Out[i] = 10 + expected[i];
117 }
118 return TRUE;
119}
120
121extern "C" DLL_EXPORT BOOL STDMETHODCALLTYPE PassArrayShort(
122 SHORT shortArray[], SHORT shortArray_In[], SHORT shortArray_InOut[], SHORT shortArray_Out[], SHORT expected[], int len){
123
124 for(int i = 0; i < len; i++)
125 {
126 if(shortArray[i] != expected[i] || shortArray_In[i] != expected[i] || shortArray_InOut[i] != expected[i])
127 {
128 printf("Not correct pass in paremeter in PassArrayShort\n");
129 return FALSE;
130 }
131 shortArray_InOut[i] = 10 + expected[i];
132 shortArray_Out[i] = 10 + expected[i];
133 }
134 return TRUE;
135}
136
137extern "C" DLL_EXPORT BOOL STDMETHODCALLTYPE PassArrayUshort(
138 USHORT ushortArray[], USHORT ushortArray_In[], USHORT ushortArray_InOut[], USHORT ushortArray_Out[], USHORT expected[], int len){
139
140 for(int i = 0; i < len; i++)
141 {
142 if(ushortArray[i] != expected[i] || ushortArray_In[i] != expected[i] || ushortArray_InOut[i] != expected[i])
143 {
144 printf("Not correct pass in paremeter in PassArrayUshort\n");
145 return FALSE;
146 }
147 ushortArray_InOut[i] = 10 + expected[i];
148 ushortArray_Out[i] = 10 + expected[i];
149 }
150 return TRUE;
151}
152
153extern "C" DLL_EXPORT BOOL STDMETHODCALLTYPE PassArrayInt(
154 int IntArray[], int IntArray_In[], int IntArray_InOut[], int IntArray_Out[], int expected[], int len){
155
156 for(int i = 0; i < len; i++)
157 {
158 if(IntArray[i] != expected[i] || IntArray_In[i] != expected[i] || IntArray_InOut[i] != expected[i])
159 {
160 printf("Not correct pass in paremeter in PassArrayInt\n");
161 return FALSE;
162 }
163 IntArray_InOut[i] = 10 + expected[i];
164 IntArray_Out[i] = 10 + expected[i];
165 }
166 return TRUE;
167}
168
169
170extern "C" DLL_EXPORT BOOL STDMETHODCALLTYPE PassArrayUint(
171 UINT uintArray[], UINT uintArray_In[], UINT uintArray_InOut[], UINT uintArray_Out[], UINT expected[], int len){
172
173 for(int i = 0; i < len; i++)
174 {
175 if(uintArray[i] != expected[i] || uintArray_In[i] != expected[i] || uintArray_InOut[i] != expected[i])
176 {
177 printf("Not correct pass in paremeter in PassArrayUint\n");
178 return FALSE;
179 }
180 uintArray_InOut[i] = 10 + expected[i];
181 uintArray_Out[i] = 10 + expected[i];
182 }
183 return TRUE;
184}
185
186extern "C" DLL_EXPORT BOOL STDMETHODCALLTYPE PassArrayLong(
187 LONG64 longArray[], LONG64 longArray_In[], LONG64 longArray_InOut[], LONG64 longArray_Out[], LONG64 expected[], int len){
188
189 for(int i = 0; i < len; i++)
190 {
191 if(longArray[i] != expected[i] || longArray_In[i] != expected[i] || longArray_InOut[i] != expected[i])
192 {
193 printf("Not correct pass in paremeter in PassArrayLong\n");
194 return FALSE;
195 }
196 longArray_InOut[i] = 10 + expected[i];
197 longArray_Out[i] = 10 + expected[i];
198 }
199 return TRUE;
200}
201
202extern "C" DLL_EXPORT BOOL STDMETHODCALLTYPE PassArrayUlong(
203 LONG64 ulongArray[], LONG64 ulongArray_In[], LONG64 ulongArray_InOut[],
204 LONG64 ulongArray_Out[], LONG64 expected[], int len){
205
206 for(int i = 0; i < len; i++)
207 {
208 if(ulongArray[i] != expected[i] || ulongArray_In[i] != expected[i] || ulongArray_InOut[i] != expected[i])
209 {
210 printf("Not correct pass in paremeter in PassArrayUlong\n");
211 return FALSE;
212 }
213 ulongArray_InOut[i] = 10 + expected[i];
214 ulongArray_Out[i] = 10 + expected[i];
215 }
216 return TRUE;
217}
218
219extern "C" DLL_EXPORT BOOL STDMETHODCALLTYPE PassArraySingle(
220 float singleArray[], float singleArray_In[], float singleArray_InOut[],
221 float singleArray_Out[], float expected[], int len){
222
223 for(int i = 0; i < len; i++)
224 {
225 if(singleArray[i] != expected[i] || singleArray_In[i] != expected[i] || singleArray_InOut[i] != expected[i])
226 {
227 printf("Not correct pass in paremeter in PassArraySingle\n");
228 return FALSE;
229 }
230 singleArray_InOut[i] = 10 + expected[i];
231 singleArray_Out[i] = 10 + expected[i];
232 }
233 return TRUE;
234}
235
236extern "C" DLL_EXPORT BOOL STDMETHODCALLTYPE PassArrayDouble(
237 double doubleArray[], double doubleArray_In[], double doubleArray_InOut[], double doubleArray_Out[], double expected[], int len){
238
239 for(int i = 0; i < len; i++)
240 {
241 if(doubleArray[i] != expected[i] || doubleArray_In[i] != expected[i] || doubleArray_InOut[i] != expected[i])
242 {
243 printf("Not correct pass in paremeter in PassArrayDouble\n");
244 return FALSE;
245 }
246 doubleArray_InOut[i] = 10 + expected[i];
247 doubleArray_Out[i] = 10 + expected[i];
248 }
249 return TRUE;
250}
251
252extern "C" DLL_EXPORT BOOL STDMETHODCALLTYPE PassArrayChar(
253 CHAR charArray[], CHAR charArray_In[], CHAR charArray_InOut[], CHAR charArray_Out[], CHAR expected[], int len){
254 for(int i = 0; i < len; i++)
255 {
256 if(charArray[i] != expected[i] || charArray_In[i] != expected[i] || charArray_InOut[i] != expected[i])
257 {
258 printf("Not correct pass in paremeter in PassArrayChar\n");
259 return FALSE;
260 }
261 }
262
263 charArray_InOut[0] = 100;
264 charArray_Out[0] = 100;
265 charArray_InOut[1] = 101;
266 charArray_Out[1] = 101;
267 charArray_InOut[2] = 102;
268 charArray_Out[2] = 102;
269
270 return TRUE;
271}
272
273extern "C" DLL_EXPORT BOOL STDMETHODCALLTYPE PassArrayBool(
274 BOOL boolArray[], BOOL boolArray_In[], BOOL boolArray_InOut[], BOOL boolArray_Out[], BOOL expected[], int len){
275
276 for(int i = 0; i < len; i++)
277 {
278 if(boolArray[i] != expected[i] || boolArray_In[i] != expected[i] || boolArray_InOut[i] != expected[i])
279 {
280 printf("Not correct pass in paremeter in PassArrayBool\n");
281 return FALSE;
282 }
283 }
284
285 boolArray_InOut[0] = FALSE;
286 boolArray_Out[0] = FALSE;
287 boolArray_InOut[1] = TRUE;
288 boolArray_Out[1] = TRUE;
289 boolArray_InOut[2] = TRUE;
290 boolArray_Out[2] = TRUE;
291
292 return TRUE;
293}
294
295extern "C" DLL_EXPORT BOOL STDMETHODCALLTYPE PassArrayIntPtr(
296 INT_PTR intPtrArray[], INT_PTR intPtrArray_In[], INT_PTR intPtrArray_InOut[], INT_PTR intPtrArray_Out[], INT_PTR expected[], int len){
297
298 for(int i = 0; i < len; i++)
299 {
300 if(intPtrArray[i] != expected[i] || intPtrArray_In[i] != expected[i] || intPtrArray_InOut[i] != expected[i])
301 {
302 printf("Not correct pass in paremeter in PassArrayIntPtr\n");
303 return FALSE;
304 }
305 intPtrArray_InOut[i] = 10 + expected[i];
306 intPtrArray_Out[i] = 10 + expected[i];
307 }
308 return TRUE;
309}
310
311extern "C" DLL_EXPORT BOOL STDMETHODCALLTYPE PassArrayUIntPtr(
312 UINT_PTR uIntPtrArray[], UINT_PTR uIntPtrArray_In[], UINT_PTR uIntPtrArray_InOut[], UINT_PTR uIntPtrArray_Out[], UINT_PTR expected[], int len){
313
314 for(int i = 0; i < len; i++)
315 {
316 if(uIntPtrArray[i] != expected[i] || uIntPtrArray_In[i] != expected[i] || uIntPtrArray_InOut[i] != expected[i])
317 {
318 printf("Not correct pass in paremeter in PassArrayUIntPtr\n");
319 return FALSE;
320 }
321 uIntPtrArray_InOut[i] = 10 + expected[i];
322 uIntPtrArray_Out[i] = 10 + expected[i];
323 }
324 return TRUE;
325}
326
327extern "C" DLL_EXPORT BOOL STDMETHODCALLTYPE PassMixStruct(AsAnyField mix){
328 return TRUE;
329}
330