在VC6.0对话框中调用DLL,出错。
原程序如下:(为了调试,写在了按钮中)
void CMyTestDlg::OnButton2()
{
int li_return;
typedef long(*pRpcOpen)(long portid,long baudrate);
HINSTANCE hDLL;
pRpcOpen RpcOpen;
hDLL=LoadLibrary("mw_p210.dll");//加载动态链接库文件;
if (hDLL==NULL)
{
MessageBox("fail");
}
RpcOpen=(pRpcOpen)GetProcAddress(hDLL,"RpcOpen");
if(NULL==RpcOpen)
{ AfxMessageBox(" fails",MB_OK,0);
return ;
}
li_return = RpcOpen(2,38400);//这步出错
if(li_return!=1)
{
MessageBox("请重新启动计算机!");
RpcClose();
}
FreeLibrary(hDLL);
//End
}错误如下:
Debug Error!
Program:D:\当前工作目录\DLL\VCTRY\MyTest\Debug\MyTest.exe
Module:
File:i386\chkesp.c
Line:42The 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.小弟接触DLL时间不长,望各位高手指点。
原程序如下:(为了调试,写在了按钮中)
void CMyTestDlg::OnButton2()
{
int li_return;
typedef long(*pRpcOpen)(long portid,long baudrate);
HINSTANCE hDLL;
pRpcOpen RpcOpen;
hDLL=LoadLibrary("mw_p210.dll");//加载动态链接库文件;
if (hDLL==NULL)
{
MessageBox("fail");
}
RpcOpen=(pRpcOpen)GetProcAddress(hDLL,"RpcOpen");
if(NULL==RpcOpen)
{ AfxMessageBox(" fails",MB_OK,0);
return ;
}
li_return = RpcOpen(2,38400);//这步出错
if(li_return!=1)
{
MessageBox("请重新启动计算机!");
RpcClose();
}
FreeLibrary(hDLL);
//End
}错误如下:
Debug Error!
Program:D:\当前工作目录\DLL\VCTRY\MyTest\Debug\MyTest.exe
Module:
File:i386\chkesp.c
Line:42The 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.小弟接触DLL时间不长,望各位高手指点。
你把调用方式改一下应该就可以了
DLL不是我自己写的,只是调用,只知道参数。PS:但我在PB里调用就可以,不知道问题出在哪里!
而且我自己写出的DLL,在这里调用也可以!
改成
typedef long(__stdcall *pRpcOpen)(long portid,long baudrate);