在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
C++中函数定义: extern "C" __declspec(dllexport) void CharArray(char* cArray) { printf("%s", cArray); } extern "C" __declspec(dllexport) void IntRef(int & iRef) { iRef = 999; } extern "C" __declspec(dllexport) void FloatArray(float* fArray,int size) { for (int i=0;i<size;++i) { fArray[i] = 6.6f; } } C#中调用: class Program { [DllImport("foo.dll",EntryPoint = "CharArray", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)] public static extern void CharArray([MarshalAs(UnmanagedType.LPStr)]string cArray); [DllImport("foo.dll", EntryPoint = "IntRef", CallingConvention = CallingConvention.Cdecl)] public static extern void IntRef(ref int iRef); [DllImport("foo.dll", EntryPoint = "FloatArray", CallingConvention = CallingConvention.Cdecl)] public static extern void FloatArray(float[] fArray, int size); static void Main() { int counter = 0; float[] farr =new float[6]; string path = "c:\\foo\\bar"; CharArray(path); FloatArray(farr, 6); IntRef(ref counter); Console.WriteLine(counter); for (int i = 0; i < 6; i++) { Console.WriteLine(farr[i]); } } }
|
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论