C++编译DLL
这里以C++编译数组排序为例1
2
3
4
5
6
7
8
9
10
11
12
13
14
15extern "C" __declspec(dllexport) void array_sort(int* a, int len)
{
for (int i = 0; i < len; i++)
{
for (int j = i + 1; j < len; j++)
{
if (a[i] > a[j])
{
int tmp = a[i];
a[i] = a[j];
a[j] = tmp;
}
}
}
}
注意库的编译方式x86/x64/Debug/Release
C#调用DLL
1 | using System.Runtime.InteropServices; |
同样需要注意库的编译方式x86/x64/Debug/Release,C#中默认为Any CPU