HINSTANCE hJB8800;
typedef int (*HS_STATE)(int);
HS_STATE hs_state;
typedef int (*OPENPORT)(int);
OPENPORT openport;
typedef void (*CLOSEPORT)();
CLOSEPORT closeport;hJBdll=LoadLibrary("JB8800.dll");
hs_state=(HS_STATE)GetProcAddress(hJBdll,"hs_state");
openport=(OPENPORT)GetProcAddress(hJBdll,"openport");
closeport=(CLOSEPORT)GetProcAddress(hJBdll,"closeport");下面是调用:
int result;
r=hs_state(5);
if(r==119)
return;
else 
{
result=openport(r);
if(result==1)
{
MessageBox("成功加载动态链接库!");
closeport();
}
else
MessageBox("加载动态链接库失败!");
}
编译可以通过,但在调试时,单步执行到接口函数调用的地方就会弹出错误提示框,错误信息是:
The value of ESP was not properly saved across a function call.This is usually a result of caling a function declared with one calling convetion with a function pointer declared with a different calling convention.请大家帮我看看,到底是哪里出问题了,我这边很急,谢谢了!

解决方案 »

  1.   

    函数类型定义不对
    typedef int (*HS_STATE)(int);
    typedef int (*OPENPORT)(int);
    typedef void (*CLOSEPORT)();
    这三个定义中有一个和DLL中实际定义不一样
      

  2.   

    dll中的定义跟你的不一致
    造成函数寻址错误
      

  3.   

    这三个接口函数调用的地方都会弹出错误提示对话框,我检查过了,我的函数定义没错类型和参数跟dll中的一样,还可能是什么原因啊?
      

  4.   

    hs_state=(HS_STATE)GetProcAddress(hJBdll,"hs_state");
    返回的hs_state正确么?
      

  5.   

    如何检查返回的hs_state正确与否啊?
      

  6.   

    DLL中每个导出函数前加 APIENTRY / WINAPI / __stdcall 都一样!
    缺省使用__cdecl 方式 具体区别自己查吧。