如果在C++里声明的函数形参原型是char*,那么我会这样子调用:
C++ API原型如下:
extern "C"{
_declspec(dllexport) void fun(unsigned char* ){
// 此处省略...
}
}
则,在C# 调用与声明如下:
[DllImport("你的动态链接库名称.dll", CallingConvention = CallingConvention.Cdecl)]
public static extern void fun(StringBuilder sb); // 采用StringBuilder
C++中 unsigned char*==C# byte[]
C++
void fun(unsigned char* );
C#
void fun(ref byte);
比如数据是这样的
byte[] aa=new byte[2]{0x01,0x02};
调用的时候
fun(ref aa[0]);