C++代码:
struct a
{
    int x;
    b y[10];
    c z[10];//b,c都是下面定义的结构体
}struct b
{
   int aa;
   int bb;
}struct c
{
   float cc;
   double dd;
}导出函数:
int GetInfo(a* pINFO)C#里面该怎么定义结构体a,并调用函数GetInfo,读取pInfo地址里的值?烦恼了一天,也没找出好的解决办法,请大家帮帮忙,谢谢

解决方案 »

  1.   

    int GetInfo(ref a pINFO)
    这样行不?
    或是看看
      

  2.   

    [System.Runtime.InteropServices.StructLayout( System.Runtime.InteropServices.LayoutKind.Explicit)]
    属性。具体的这个要测试才能知道对不对。只给你个方向。懒得弄vc项目测试了。
      

  3.   

    C#调用C中的函数
    相应参数(结构体)需要自己重新定义  
    char[] 对应 string 
    int 对应 int32 
    long 对应int64
    指针 对应 intptr
    。。导入C函数
    [Dllimport("你的dll.dll")]
    public static extern int GetInfo(ref yourStruct info);结构体定义
    [StructLayout(LayoutKind.Sequential)]
    struct yourStruct
    {
      //成员定义。要跟C中对应
    }
      

  4.   

    我想知道的是,我在C#中是否一样可以嵌套定义结构体,我在C#中如果同样定义下面的结构体是否能跟C++的对应上。
    [StructLayout(LayoutKind.Sequential)]
    struct a
    {
      int x;
      b y[10];
      c z[10];//b,c都是下面定义的结构体
    }[StructLayout(LayoutKind.Sequential)]
    struct b
    {
      int aa;
      int bb;
    }[StructLayout(LayoutKind.Sequential)]
    struct c
    {
      float cc;
      double dd;
    }
      

  5.   

    [StructLayout(LayoutKind.Sequential)]
    struct a
    {
      int x;
      b[] y;
      c[] z;//b,c都是下面定义的结构体
    }
    这里面的y和z都是数组,不用特殊说明吗?
    我记得连int数组都要向下面这样定义
    [MarshalAs(UnmanagedType.ByValArray, sizeConst = 6)]
    public int[] test;