日期:2014-05-17  浏览次数:20746 次

求教C#调用DLL参数为数组指针如何传参
源声明:

int __stdcall fun(unsigned char *srcdata, int *number, unsigned char *tagdata[4]) ;


在C#中应该如何调用传参啊 , 
求教求教~~

我目前的代码:

               int number = 4;
                byte[,] result = new byte[4, 100];
                IntPtr[] ptArray = new IntPtr[4];
                ptArray[0] = Marshal.AllocHGlobal(100);
                ptArray[1] = Marshal.AllocHGlobal(100);
                ptArray[2] = Marshal.AllocHGlobal(100);
                ptArray[3] = Marshal.AllocHGlobal(100);
                fucn(buf, ref number, ptArray); // 调用
                for (int i = 0; i < number; i++)
                {
                    for (int j = 0; j < 100; j++)
                    {
                        byte b = 0;
                        b = (byte)Marshal.PtrToStructure((IntPtr)((UInt32)ptArray[i] + j), b.GetType());
                        result[i, j] = b;
                    }
                }
                Console.WriteLine();
                Marshal.FreeHGlobal(ptArray[0]);
                Marshal.FreeHGlobal(ptArray[1]);
                Marshal.FreeHGlobal(ptArray[2]);
                Marshal.FreeHGlobal(ptArray[3]);


但是数据不对啊 , 我猜想我的代码写错了, 网上苦寻很久  仍未找到方法 , 求教各位啦 ..

------解决方案--------------------
unsigned char *srcdata 用 stringbuilder
int *number 这个要用到unsafe的int