| 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 | #include <stdlib.h> | 
| 8 | |
| 9 | const int LEN = 10; | 
| 10 | extern "C"BOOL DLL_EXPORT __cdecl MarshalRefCharArray_Cdecl(char ** pstr) | 
| 11 | { | 
| 12 | //Check the Input | 
| 13 | for(int i = 0; i < LEN; i++) | 
| 14 | { | 
| 15 | if((*pstr)[i]!=('a'+i)) | 
| 16 | { | 
| 17 | printf( "MarshalRefCharArray_Cdecl: The value item %d is wrong",i+1); | 
| 18 | return FALSE; | 
| 19 | } | 
| 20 | } | 
| 21 | |
| 22 | //Change the value | 
| 23 | for(int i = 0;i<LEN;i++) | 
| 24 | { | 
| 25 | (*pstr)[i] = 'z'; | 
| 26 | } | 
| 27 | return TRUE; | 
| 28 | } | 
| 29 | extern "C"BOOL DLL_EXPORT __stdcall MarshalRefCharArray_Stdcall(char ** pstr) | 
| 30 | { | 
| 31 | //Check the Input | 
| 32 | for(int i = 0;i < LEN;i++) | 
| 33 | { | 
| 34 | if((*pstr)[i]!=('a'+i)) | 
| 35 | { | 
| 36 | printf( "MarshalRefCharArray_Cdecl: The value item %d is wrong",i+1); | 
| 37 | return FALSE; | 
| 38 | } | 
| 39 | } | 
| 40 | |
| 41 | //Change the value | 
| 42 | for(int i = 0;i<LEN;i++) | 
| 43 | { | 
| 44 | (*pstr)[i] = 'z'; | 
| 45 | } | 
| 46 | return TRUE; | 
| 47 | } | 
| 48 | |
| 49 | typedef BOOL(__cdecl *CdeclCallBack)(char ** pstr); | 
| 50 | extern "C"BOOL DLL_EXPORT __cdecl DoCallBack_MarshalRefCharArray_Cdecl(CdeclCallBack caller) | 
| 51 | { | 
| 52 | char * str = (char*)CoreClrAlloc(LEN); | 
| 53 | for(int i = 0;i<LEN;i++) | 
| 54 | { | 
| 55 | str[i] = 'z'; | 
| 56 | } | 
| 57 | if(!caller(&str)) | 
| 58 | { | 
| 59 | printf( "DoCallBack_MarshalRefCharArray_Cdecl:The Caller returns wrong value.\n"); | 
| 60 | return FALSE; | 
| 61 | } | 
| 62 | if(str[0]!='a') | 
| 63 | { | 
| 64 | CoreClrFree(str); | 
| 65 | return FALSE; | 
| 66 | } | 
| 67 | return TRUE; | 
| 68 | } | 
| 69 | |
| 70 | typedef BOOL(__stdcall *StdCallBack)(char ** pstr); | 
| 71 | extern "C"BOOL DLL_EXPORT __stdcall DoCallBack_MarshalRefCharArray_Stdcall(StdCallBack caller) | 
| 72 | { | 
| 73 | char * str = (char*)CoreClrAlloc(LEN); | 
| 74 | for(int i = 0;i<LEN;i++) | 
| 75 | { | 
| 76 | str[i] = 'z'; | 
| 77 | } | 
| 78 | if(!caller(&str)) | 
| 79 | { | 
| 80 | printf( "DoCallBack_MarshalRefCharArray_Stdcall:The Caller returns wrong value.\n"); | 
| 81 | return FALSE; | 
| 82 | } | 
| 83 | if(str[0]!='a') | 
| 84 | { | 
| 85 | |
| 86 | CoreClrFree(str); | 
| 87 | return FALSE; | 
| 88 | } | 
| 89 | return TRUE; | 
| 90 | } | 
| 91 | |
| 92 | typedef BOOL (__cdecl * DelegatePInvoke_Cdecl)(char **pstr); | 
| 93 | extern "C"DLL_EXPORT DelegatePInvoke_Cdecl __cdecl DelegatePinvoke_Cdecl() | 
| 94 | { | 
| 95 | return MarshalRefCharArray_Cdecl; | 
| 96 | } | 
| 97 | |
| 98 | typedef BOOL (__stdcall * DelegatePInvoke_Stdcall)(char **pstr); | 
| 99 | extern "C"DLL_EXPORT DelegatePInvoke_Stdcall __stdcall DelegatePinvoke_Stdcall() | 
| 100 | { | 
| 101 | return MarshalRefCharArray_Stdcall; | 
| 102 | } | 
