summaryrefslogtreecommitdiff
path: root/tests/src/Interop/SimpleStruct/SimpleStructNative.cpp
blob: fb855a42e871375ddcdb02cd66796794edca887c (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
103
104
105
106
107
#include "platformdefines.h"

#include <stdio.h>
#include <stdlib.h>
#include <xplatform.h>

typedef void *voidPtr;
 
typedef struct { int a; 
bool b;
char* str;} Sstr;

typedef struct { int a; 
bool b;
double c;} Sstr_simple;

typedef struct { 
	int a;
	int extra; //padding needs to be added here as we have added 8 byte offset.
	union
	{
		int i;
		BOOL b;
		double d;
	}udata;
}ExplStruct;

extern "C"
DLL_EXPORT BOOL _cdecl CdeclSimpleStructByRef(Sstr *p) 
{
  p->a = 100;
  p->b=1;
  strcpy_s(p->str, 7, "after");
  return TRUE;
}

extern "C"
DLL_EXPORT BOOL _cdecl CdeclSimpleExplStructByRef(ExplStruct *p)
{
	if((p->a != 0) || (p->udata.i != 10))
	{
		printf("\np->a=%d, p->udata.i=%d\n",p->a,p->udata.i);
		return FALSE;
	}
	p->a = 1;
	p->udata.b = TRUE;
	return TRUE;
}

extern "C"
DLL_EXPORT Sstr_simple* _cdecl CdeclSimpleStruct(Sstr_simple p,BOOL *result)
{
	Sstr_simple *pSimpleStruct;
	if((p.a !=100) || (p.b != FALSE) || (p.c != 3.142))
	{
		*(result)= FALSE;
		return NULL;
	}
	pSimpleStruct = (Sstr_simple*) TP_CoTaskMemAlloc(sizeof(Sstr_simple) * 1);
	pSimpleStruct->a = 101;
	pSimpleStruct->b = TRUE;
	pSimpleStruct->c = 10.11;
	*(result)= TRUE;
	return pSimpleStruct;
}

extern "C"
DLL_EXPORT ExplStruct* _cdecl CdeclSimpleExplStruct(ExplStruct p,BOOL *result)
{
	ExplStruct *pExplStruct;
	if((p.a !=1) || (p.udata.b != FALSE))
	{
		*(result)= FALSE;
		return NULL;
	}
	pExplStruct = (ExplStruct*) TP_CoTaskMemAlloc(sizeof(ExplStruct) * 1);
	pExplStruct->a = 2;
	pExplStruct->udata.d = 3.142;
	*(result)= TRUE;
	return pExplStruct;
}

extern "C"
DLL_EXPORT voidPtr __stdcall GetFptr(int i)
{
	switch(i)
	{

	case 14:
		return (voidPtr) &CdeclSimpleStructByRef;
		break;

	case 16:
		return (voidPtr) &CdeclSimpleStruct;
		break;

	case 18:
		return (voidPtr) &CdeclSimpleExplStructByRef;
		break;

	case 20:
		return (voidPtr) &CdeclSimpleExplStruct;
		break;

	}
	return (voidPtr) &CdeclSimpleStruct;
}