DLL函数动态加载

来源:互联网 发布:足球意大利克德国知乎 编辑:程序博客网 时间:2024/06/10 01:19
问题1:
        我在动态调用ZLIB.DLL中的uncompress和compress时出现 Debug Error! 提示 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.
解决方法:
      调步调试,在函数返回时堆栈有4个字节的参数没有谈出.我将我的原始调用方法:
      typedef int  (WINAPI *ZLIBCOMPRESS) ( Bytef  *dest ,   uLongf *destLen , const Bytef *source , uLong sourceLen);
t    ypedef int  (WINAPI*ZLIBUNCOMPRESS) (Bytef *dest,   uLongf *destLen , const Bytef *source, uLong sourceLen);
      改为:
typedef int  (__cdecl *ZLIBCOMPRESS) ( Bytef  *dest ,   uLongf *destLen , const Bytef *source , uLong sourceLen);
typedef int  ( __cdecl *ZLIBUNCOMPRESS) (Bytef *dest,   uLongf *destLen , const Bytef *source, uLong sourceLen);
     程序就OK.
结论:调用约定不匹配造成的

问题2:
    DLL注入出现提示 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.
解决方法:
      DLL中的代码
void doIt2(){
mbox("start");
__asm{
pushad
mov eax, code //参数
push eax
mov edx, 0x00401019 //函数地址
call edx
popad
}
mbox("over");
}
在弹出"over"之后就会弹出这个错误提示,如何能解决?


解决:::::::::::::::::
使用MFC写出来的函数它都会在后面给你加一个chkesp()函数,来判断堆栈是否正确,
从你代码上看
pushad
push eax
call edx
add esp,4  <-- 这里得加上才行
popad

结论:
       调用约定不匹配造成的
原创粉丝点击