小编6se*_*ine的帖子

将 double[,] 转换为 IntPtr C#

我需要将 c# 中的双数组转换为 IntPtr 以将其正确发送到我的 c DLL。我已经成功地使用这个答案中的方法从IntPtr 转换为 double[,] 。我还找到了另一个接近我需要但处理一维数组的答案

我在我的逻辑中遗漏了一些东西并在崩溃后得到错误代码:Managed ' has exited with code -1073740940 (0xc0000374)。

这是我到目前为止

            IntPtr p = Marshal.AllocHGlobal(rows * columns);
            for (int i = 0; i < rows; i++) //rows
            {
                double[] temp = new double[columns];

                for (int x = 0; x < columns; x++)
                    temp[x] = input.cells[i, x];

                Marshal.Copy(temp, 0, p, columns);

                p = (IntPtr)(p.ToInt64() + IntPtr.Size);
            }

            toReturn.cells = p;
            Marshal.FreeHGlobal(p);
            return toReturn;
Run Code Online (Sandbox Code Playgroud)

toReturn.cells 是我返回的结构内的 IntPtr。单元格的结构为单元格[行,列] …

c# double intptr

3
推荐指数
1
解决办法
87
查看次数

标签 统计

c# ×1

double ×1

intptr ×1