小弟在自己写的一个dll中调用另一个dll,结果在dll1装入dll2后,一到调用dll2的函数的时候就出现以下错误:Debug error!Program:...\Test1.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 on calling convention with a function pointer declared with a different calling convention.并且,小弟将dll2文件删除,还是出现这个错误信息,而且此时检查LoadLibrary("MyDll")发现其返回值并不为空,请教各位高手该如何处理,多谢,马上给分。
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 on calling convention with a function pointer declared with a different calling convention.并且,小弟将dll2文件删除,还是出现这个错误信息,而且此时检查LoadLibrary("MyDll")发现其返回值并不为空,请教各位高手该如何处理,多谢,马上给分。
举个例子:如果你的DLL导出函数定义是int f(){ },那么把它换成int WINAPI f(){ }试试看。
看看你的调用和声明是否一致。看看你的工程属性,project-->setting-->c++->code generation-->calling convention, 是__stdcall,还是__cdcel
WINAPI加上了也不行阿
To tserpent(Tang):
calling convention我已经统一了,可还是不行
To flyelf(空谷清音:
请问函数入栈方式如何统一呢我的代码如下,是不是本身有问题呢:
我用vb程序静态调用MyDll1.dll,在MyDll1.dll中调用MyDll2.dll
MyDll1.h
#ifdef MYDLL1_EXPORTS
#define MYDLL1_API __declspec(dllexport)
#else
#define MYDLL1_API __declspec(dllimport)
#endif
int LoadDll();
void ExitDll();
int DoCalculate(int Code);
MyDll1.cpp
#include "stdafx.h"
#include "MyDll1.h"
static HINSTANCE DLLInst = NULL; //动态库句柄
typedef int(*CALCULATE)(int);
CALCULATE Calculate;
int LoadDll()
{
DLLInst=LoadLibrary("MyDll1.dll");
if(DLLInst!=NULL)
{
Calculate=(CALCULATE)GetProcAddress(DLLInst,"Calculate");
return(0);
}
else
{
::MessageBox(NULL,"加载动态库失败!", "提示信息", MB_OK | MB_ICONINFORMATION);
return(1);
}
}
void ExitDll()
{
if(DLLInst!=NULL)
FreeLibrary(DLLInst);
}
int DoCalculate(int code)
{
return Calculate(code);
}
MyDll1.def
LIBRARY "MyDll1"
EXPORTS
LoadDll @1
ExitDll @2
DoCalculate @3MyDll2.h
#ifdef MYDLL2_EXPORTS
#define MYDLL2_API __declspec(dllexport)
#else
#define MYDLL2_API __declspec(dllimport)
#endif
int Calculate(int Code);
MyDll2.cpp
#include "stdafx.h"
#include "SimpleDll.h"
int Calculate(int Code)
{
switch(Code)
{
case 0:
return (1);
break;
case 1:
return (2);
break;
case 2:
return (3);
break;
case 3:
return (4);
break;
case 4:
return (5);
break;
case 5:
return (6);
break;
case 6:
return (7);
break;
}
}MyDll2.def
LIBRARY "MyDll2"
EXPORTS
Calculate @1
最好是用RELEASE编译
用release编译也试过了 还是不行
问题应该还是在那个calling convention上吧
还有就是小弟一直搞不懂为什么无论MyDll2.dll文件是否存在
LoadLibrary("MyDll2.dll")的结果都不是Null,这是怎么回事阿
(例如system32, vc安装的目录等等)