在使用第三方的非托管API时,我们经常会遇到参数为指针或指针的指针这种情况,
, f6 T; ?. u4 o 一般我们会用IntPtr指向我们需要传递的参数地址; ( Y5 L" K5 P4 C b
但是当遇到这种一个导出函数时,我们如何正确的使用IntPtr呢, 0 x+ D! ~6 ^, C3 P2 } }: `% m
extern “C” __declspec(dllexport) int GetClass(Class pClass[50]) ; 1 J, M" z; H! z/ z- o
由于这种情况也经常可能遇到,所以我制作了2个示例程序来演示下如何处理这种非托管函数的调用!
7 p7 J2 M8 Z p. z7 b5 K% `' Q 首先创建一个C++ 的DLL 设置一个如上的导出函数 * a# K: [. d |% G+ H
#include #include typedef struct Student { char name[20];int age;double scores[32];}Student;typedef struct Class { int number;Student students[126];}Class;extern “C” __declspec(dllexport) int GetClass(Class pClass[50])
' p3 }+ L* N% y1 D2 v, k& H$ P { for(int i=0;i |