| 1 | #include <platformdefines.h> |
|---|---|
| 2 | |
| 3 | #include <stdio.h> |
| 4 | #include <stdlib.h> |
| 5 | #include <xplatform.h> |
| 6 | |
| 7 | typedef void *voidPtr; |
| 8 | |
| 9 | typedef struct { int a; |
| 10 | bool b; |
| 11 | char* str;} Sstr; |
| 12 | |
| 13 | typedef struct { int a; |
| 14 | bool b; |
| 15 | double c;} Sstr_simple; |
| 16 | |
| 17 | typedef 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 | |
| 28 | extern "C" |
| 29 | DLL_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 | |
| 37 | extern "C" |
| 38 | DLL_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 | |
| 50 | extern "C" |
| 51 | DLL_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 | |
| 67 | extern "C" |
| 68 | DLL_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 | |
| 83 | extern "C" |
| 84 | DLL_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 |