首页 > Linux操作系统 > Linux操作系统 > C#调用c++编写的dll
c++文件中函数定义如下:
extern "C"
{
//__stdcall即callback
__declspec(dllexport) int __stdcall f_Test(unsigned char pInput[], char ifn[100])
{
return 1;
}
}
c#文件中函数调用如下:
[DllImport("Test.dll")]//Test.dll是c++文件生成的dll
static extern int f_Test(byte[] pInput, String fileName);
byte[] Minput = new byte[100];
f_Test(Minput, fileName);
如果传递的参数为结构体,则必须在c#端定义数据成员类型相对应的结构体。
struct point{
unsigned short xpos;
unsigned short ypos;
} ;
C#端定义如下:
public struct point
{
public ushort xpos;
public ushort ypos;
};
来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/12639172/viewspace-566847/ ,如需转载,请注明出处,否则将追究法律责任。