用c调用opencv库,实现了一个dll文件,现在需要用wpf 进行调用该库
实现的过程如下:
在 test.h 中
extern "C"
{
_declspec(dllexport) int __stdcall sub(int x,int y);
}
extern "C"
{
_declspec(dllexport) int __stdcall GetDetection(char* fpath,int leftupx);
}
test.cpp中实现函数
int __stdcall sub(int x,int y)
{
return x-y;
}
int __stdcall GetDetection(char* fpath,int leftupx)
{
//实现
}
在工程中加入test.def 文件 LIBRARY Test
EXPORTS
sub
GetDetection
库编译完成;
下面是调用:
[DllImport("Test.dll", EntryPoint = "GetDetection", CharSet = CharSet.Ansi,
CallingConvention = CallingConvention.StdCall)]
public static extern int GetDetection(string fpath, int leftupx) //这里要搞成string类型,才能调用char*
调用该函数就可以了;