本文主要记录,如何调用第三方动态库DLL,不通过隐式调用,没有.h文件和.lib文件;但已知函数的接口定义,DLL中方法的名称以及参数类型,接下来讲解的是如何让其中的方法为我们所用,以下是详细步骤:
1.加载DLL
HINSTANCE hdll = NULL;
CString dllPath = "DLL所在的路径";
hdll = LoadLibrary(dllPath + _T("Test.dll"));
if (hPDdll == NULL)
{
printf("Failed to load Test.dll");
return;
}
2.定义及加载函数接口类型
//定义接口类型
typedef int (*FNUC_GETCALIDATA)(int type, UCHAR* cali_buffer,BYTE * RawBuffer,UINT
Num,int Pos);
//定义变量
FNUC_GETCALIDATA pd_getcalidata = NULL;
//加载函数接口
getdata = (FNUC_GETCALIDATA)GetProcAddress(hdll, "CalibMethod");
if (getdata == NULL)
{
printf("Failed to GetProcAddress getdata");
return;
}
3.调用接口
Byte* rawBuf = new Byte[buffersize]
UCHAR* output = new UCHAR[size];
memset(output,0,sizeof(output));
int iret = getdata(0, output,rawBuf,0,0);