C#调用C++动态库结构体函数得到所有结构体信息,旷世难题,高手请进!!!!!!!!!1

lcmlhs_2005 lcmlhs_2005 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
C++中有
typedef struct Student
{
char name[24];
int age;
}StudentInfo;

int GetStudentInfo(StudentInfo * pStudentInfo);//返回学生结构体个数

上面的函数存在于Student.dll中,下面要在C#里调用Student.dll中的这个函数:

public struct Student
{
public char[] name;
public int age;
}

[DllImport("Student.dll",CharSet = CharSet.Ansi)]
public static extern int(ref Student refStudent);

Student ref_student = new Student();
int count = GetStudentInfo(ref ref_student);//这里取得学生结构体的个数
char[] cname;
cname=new char[24*count];

for(int i=0;i<count;i++)
{
cname[i]=ref_student.name //这里怎样写呢?我要通过这个循环得到所有结构体里的学生名字????
}
...全文

相关推荐

评论 17
收藏 已收藏
分享
返回顶部
lcmlhs_2005
C# 111,128 成员 642,536 内容