本帖最后由 wsw0515 于 2011-09-21 10:26:46 编辑

解决方案 »

  1.   

    myconfig pConfig;
    doconfig(ref pConfig);
    ref传值一般是在函数内部会对参数重新赋值的,所以你无需赋初始值,如果一定要赋初始值,也无关紧要
      

  2.   

    public IntPtr shortArray;//short数组指针
    主要是不知道这部分怎么赋值
      

  3.   

    楼主,你把myconfig结构体的C++代码贴出来
      

  4.   

    typedef struct myconfig
    {
       ushort max;
       ushort min;
       ushort *array;
    }
    这是c++结构体文档说明
      

  5.   

    也就是说,array的大小是max-min ,对吧?
      

  6.   

    myconfig cfg=new myconfig ();cfg.max =100;
    max.min =0;
    ushort[] ary=new ushort[100]{0};
    //自己给ary赋值int size=sizeof(ushort)*(cfg.max-max.min);
    IntPtr buffer = Marshal.AllocHGlobal(size);
    Marshal.StructureToPtr(structure, buffer, false);
    cfg.shortArray=buffer ;  //这里给指针赋值!
      

  7.   

    谢谢各位,我的可以了
    用Marshal.Copy将数组拷贝到我所创建的直接就可以了
      

  8.   

    Marshal.StructureToPtr(structure, buffer, false);这句报错了。
      

  9.   

    对用Marshal.Copy 方法 (Int16[], Int32, IntPtr, Int32) 更直接,简单,没有必要搞得我那么复杂