平时,我们接触的平台调用,对于简单的类型,一般很容易学会。因为简单类型有直观的类型对应。而结构体,是一种自定义类型,结构体成员可能会很复杂。所以,封送结构体变量,是平台调用的一个重点,也是个难点。本节篇幅较多,将阐述如下几个内容:
(1)、结构体(指针)作为输入输出参数。
(2)、结构体(指针)作为函数返回值。
(3)、结构体中值类型数组。
(4)、结构体中的字符指针和字符数组
(5)、嵌套结构体
(6)、结构体数组
1、作为输入输出参数
C++:
typedef struct _MYPERSON{
char* first; //字符指针
char* last;
} MYPERSON, *LP_MYPERSON;
typedef struct _MYPERSON1{
char first[20]; //字符数组
char last[20];
} MYPERSON1, *LP_MYPERSON1;
typedef struct _MYARRAYSTRUCT{
bool flag;
int vals[ 3 ]; //值类型数组
} MYARRAYSTRUCT;
int TestStructInStruct1(MYPERSON pPerson);
int TestStructInStruct2(MYPERSON* pPerson);
C#:int TestStructInStruct3(MYPERSON1* pPerson);
void TestArrayInStruct( MYARRAYSTRUCT* pStruct );[ StructLayout( LayoutKind.Sequential, CharSet=CharSet.Ansi )]
public struct MyPerson {
public String first;
public String last;
}
[ StructLayout( LayoutKind