Re: [問題] DLL for C# Error:嘗試讀取或寫入受保씠…

看板C_and_CPP (C/C++)作者 (躂躂..)時間15年前 (2011/05/18 21:46), 編輯推噓2(200)
留言2則, 2人參與, 最新討論串2/2 (看更多)
※ 引述《laevatain103 (RICO)》之銘言: : C++ DLL code(win32) : extern "C" __declspec(dllexport) void two2(int**,int**); : void __declspec(dllexport) two2(int** a,int** c) : { : c[1][1]=a[1][1]; 這邊是 int x = 1; int y = 1; int w = 2; int h = 2; *(a + w*y + x) = *(c + w*y + x); 或是prototype要改成 two(int a[2][2], int c[2][2]) C/C++ 的 int** 和 int[M][N] 完全不是一樣的東西.. int[M][N] 比較像 int[M*N], 而 int** 比較像 int*[M] 在 C# 中的對照 int[,]是 C/C++的 int[M][N], 而 int[][] 才比較像 int** 因為 int[,] (或說C的int[M][N]) 有連續的性質, 所以在 marshaling (serialization) 是可以直接應對的 (在.NET的術語叫blittable) 可以直接傳不用轉 int[][] 就不行了, 你要自已手動寫 custom marshaling 所以你要嘛維度要固定 (e.g., 2*2), C compiler可以幫你換算 或是要傳M,N, 你裡面再自已換算 w*y + x -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 114.25.189.174

05/18 22:09, , 1F
謝謝大大
05/18 22:09, 1F

05/19 11:15, , 2F
精闢的講解!
05/19 11:15, 2F
文章代碼(AID): #1Dqysav6 (C_and_CPP)
文章代碼(AID): #1Dqysav6 (C_and_CPP)