char[] buf = new char[4];

解决方案 »

  1.   

    看来我的意思没说清楚
    假如在c语言做的一个动态链接库中有一个
    函数struct a * somefunc(void)在c#中调用这个函数,
    在c#中如何取出somefunc的值,找到char buf[]中的值?
    因为在c#中char []buf =new char[4];buf的地址是不固定的
    而在c语言中,buf 的地址是确定的 = a的地址 - 4;
      

  2.   

    [StructLayout(LayoutKind.Sequential)]
    public struct a
    {
        [MarshalAs( UnmanagedType.ByValArray, SizeConst=4)] 
        public char[] buf;
        public int a;
    }a a1 = somefunc(void)
      

  3.   

    [StructLayout(LayoutKind.Sequential)]
    public struct a
    {
        [MarshalAs( UnmanagedType.ByValArray, SizeConst=4)] 
        public char[] buf;
        public int a;
    }a a1 = somefunc(void)