a我考网

 找回密码
 立即注册

QQ登录

只需一步,快速开始

扫一扫,访问微社区

查看: 118|回复: 0

[程序员] 2012年软件水平初级资格程序员考试重点知识13

[复制链接]
发表于 2012-8-2 08:51:15 | 显示全部楼层 |阅读模式
 在使用第三方的非托管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
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

Archiver|手机版|小黑屋|Woexam.Com ( 湘ICP备18023104号 )

GMT+8, 2024-6-8 20:52 , Processed in 0.180582 second(s), 22 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

快速回复 返回顶部 返回列表