C#与C++之间dll的二维(多维)数组传递
生活随笔
收集整理的這篇文章主要介紹了
C#与C++之间dll的二维(多维)数组传递
小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
思維:用結(jié)構(gòu)體作為中間變量,也就是傳遞結(jié)構(gòu)體,然后在C#中把結(jié)構(gòu)體中的數(shù)據(jù)放進(jìn)二維數(shù)組中。
C#接收代碼的形式:(這里只是思路展示,非可運(yùn)行代碼)
[DllImport("myDLL.dll", CallingConvention = CallingConvention.Cdecl)]public static extern void myFunc([In][MarshalAs(UnmanagedType.LPArray, SizeConst = 0)] InStruct[] istruct, [Out] [MarshalAs(UnmanagedType.LPArray, SizeConst = 0)] OutStruct[] outstruct);public struct InStruct{public int x;public int y;public int z;}public struct OutStruct{public int x;public int y;public int z;}//把C++通過(guò)結(jié)構(gòu)體接收的數(shù)據(jù),裝在二維數(shù)組中int[,] data = new int[3,100];InStruct[] instruct = new InStruct[100];OutStruct[] outstruct = new OutStruct[100];//在二維數(shù)組data中接收outstruct中的數(shù)據(jù)C++中封裝的形式:
struct InStruct {int x;int y;int z; }; struct OutStruct {int x;int y;int z; }; extern "C" __declspec(dllexport) void myFunc(InStruct *instruct, OutStruct *outstruct) {InStruct instruct[100];OutStruct outstruct[100];//使用結(jié)構(gòu)體對(duì)象傳進(jìn)來(lái)或者傳出去數(shù)據(jù),可以把二維數(shù)組的數(shù)據(jù)先賦給結(jié)構(gòu)體 }總結(jié)
以上是生活随笔為你收集整理的C#与C++之间dll的二维(多维)数组传递的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: C#Winform怎么让控件随着主界面大
- 下一篇: C#lock语句用法(lock到底有什么