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