1#include <platformdefines.h>
2
3#include <stdio.h>
4#include <stdlib.h>
5#include <xplatform.h>
6
7typedef void *voidPtr;
8
9typedef struct { int a;
10bool b;
11char* str;} Sstr;
12
13typedef struct { int a;
14bool b;
15double c;} Sstr_simple;
16
17typedef struct {
18 int a;
19 int extra; //padding needs to be added here as we have added 8 byte offset.
20 union
21 {
22 int i;
23 BOOL b;
24 double d;
25 }udata;
26}ExplStruct;
27
28extern "C"
29DLL_EXPORT BOOL __cdecl CdeclSimpleStructByRef(Sstr *p)
30{
31 p->a = 100;
32 p->b=1;
33 strcpy_s(p->str, 7, "after");
34 return TRUE;
35}
36
37extern "C"
38DLL_EXPORT BOOL __cdecl CdeclSimpleExplStructByRef(ExplStruct *p)
39{
40 if((p->a != 0) || (p->udata.i != 10))
41 {
42 printf("\np->a=%d, p->udata.i=%d\n",p->a,p->udata.i);
43 return FALSE;
44 }
45 p->a = 1;
46 p->udata.b = TRUE;
47 return TRUE;
48}
49
50extern "C"
51DLL_EXPORT Sstr_simple* __cdecl CdeclSimpleStruct(Sstr_simple p,BOOL *result)
52{
53 Sstr_simple *pSimpleStruct;
54 if((p.a !=100) || (p.b != FALSE) || (p.c != 3.142))
55 {
56 *(result)= FALSE;
57 return NULL;
58 }
59 pSimpleStruct = (Sstr_simple*) CoreClrAlloc(sizeof(Sstr_simple) * 1);
60 pSimpleStruct->a = 101;
61 pSimpleStruct->b = TRUE;
62 pSimpleStruct->c = 10.11;
63 *(result)= TRUE;
64 return pSimpleStruct;
65}
66
67extern "C"
68DLL_EXPORT ExplStruct* __cdecl CdeclSimpleExplStruct(ExplStruct p,BOOL *result)
69{
70 ExplStruct *pExplStruct;
71 if((p.a !=1) || (p.udata.b != FALSE))
72 {
73 *(result)= FALSE;
74 return NULL;
75 }
76 pExplStruct = (ExplStruct*) CoreClrAlloc(sizeof(ExplStruct) * 1);
77 pExplStruct->a = 2;
78 pExplStruct->udata.d = 3.142;
79 *(result)= TRUE;
80 return pExplStruct;
81}
82
83extern "C"
84DLL_EXPORT voidPtr STDMETHODCALLTYPE GetFptr(int i)
85{
86 switch(i)
87 {
88
89 case 14:
90 return (voidPtr) &CdeclSimpleStructByRef;
91 break;
92
93 case 16:
94 return (voidPtr) &CdeclSimpleStruct;
95 break;
96
97 case 18:
98 return (voidPtr) &CdeclSimpleExplStructByRef;
99 break;
100
101 case 20:
102 return (voidPtr) &CdeclSimpleExplStruct;
103 break;
104
105 }
106 return (voidPtr) &CdeclSimpleStruct;
107}
108