C++中有
typedef struct Student
{
  char name[24];
  int age;
}StudentInfo;int GetStudentInfo(StudentInfo * pStudentInfo);//返回学生结构体个数上面的函数存在于Student.dll中,下面要在C#里调用Student.dll中的这个函数:[StructLayout(LayoutKind.Sequential)]
unsafe public struct Student
{
  public fixed char name[24];
  public int age;
}[DllImport("Student.dll",CharSet = CharSet.Ansi)]
public static extern int(Student * pStudent);Student *pstudent;
int count = GetStudentInfo(pstudent);//这里取得学生结构体的个数
char[] cname;
cname=new char[24];for(int i=0;i<count;i++)
{
  (pstudent+i)->name; //这里通过循环可以得到所有结构体里学生的名字,可是怎样赋给cname呢?如果cname类型不行,要什么类型才行呢?
}
 
 

解决方案 »

  1.   

    你这是要在C#调用C++的DLL,是要问怎么在C#中给cname赋值吗?
      

  2.   

    请参考一下这篇文章,应该有帮助。
    http://blog.csdn.net/Mittermeyer/archive/2007/04/27/1586867.aspx
    http://blog.csdn.net/Mittermeyer/archive/2009/06/27/4303434.aspx
      

  3.   

    在C++里可以用
    unsigned char cname[24];
    memset(cname,1,24);
    memcpy(cname,(pstudent+i)->name,24);  //姓名
    在循环中得到学生姓名
    在C#里要怎样得到学生姓名呢?