日期:2014-05-18 浏览次数:21331 次
extern "C" __declspec(dllexport) int* TestSetArray(IN int arr[1024]) { for(int i=0;i < 99; i++) { arr[i] = i; } return arr; }code] C#调用: [code=C#][DllImport("TestDLL.dll", EntryPoint = "Add", ExactSpelling = false, CallingConvention = CallingConvention.Cdecl)] public static extern int Add(int a, int b); [DllImport("TestDLL.dll", EntryPoint = "TestSetArray", ExactSpelling = true, CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)] public static extern int[] TestSetArray([MarshalAs(UnmanagedType.LPArray)] int[] arr); static unsafe void Main(string[] args) { Console.WriteLine(Add(1,2)); Console.WriteLine(); int[] arr = new int[1024]; int[] arr1 = TestSetArray(arr); Console.WriteLine(); Console.Read(); }