动态库调用出错
错误信息:Run-Time Check Failure #0 - The value of ESP was not properly saved across a function call. This is usually a result of calling a function declared with one calling convention with a function pointer declared with a different calling convention.
我用的是非MFC动态库dll,动态加载,有.def文件,步骤如下:
1。dll项目和测试项目在同一个工作区
2. DLL项目生成成功,把.DLL文件考贝到TEST项目的DEBUG目录下
3。把.DLL文件加到test项目中来,运行test项目
void CtestDlg::OnBnClickedBegin()
{
HINSTANCE hDll;//Dll句柄
lpSearchFun searchFun;//函数指针
hDll=LoadLibrary("SearchDll.dll");
if(hDll!=NULL)
{
searchFun=(lpSearchFun)GetProcAddress(hDll,"Search");
if(searchFun!=NULL)
{
int result=searchFun("a","a",1,"a");
CString a;
a.Format("%d",result);
AfxMessageBox(a);
}
FreeLibrary(hDll);
}
}当运行到这里(最后一个“}”)出现上述错误提示