DLL
extern "C" __declspec(dllexport) int PrinterTest(int i)
{
return 0;
}调用程序
/////////////////////////////////////////////////////////////
typedef int (STDMETHODCALLTYPE * IC_Print)(int);
HINSTANCE gLib32_DLL;
IC_Print icprint;
gLib32_DLL = LoadLibrary ("CS.dll");
if (gLib32_DLL == NULL)
{
MessageBox("-1");
return;
}
//exit IC
icprint = (IC_Print) GetProcAddress (gLib32_DLL,"PrinterTest");
if (icprint == NULL)
{
FreeLibrary (gLib32_DLL);
MessageBox("-2");
}
else
MessageBox("0"); int ret = -1;
ret = icprint(1);
编译没问题,可是运行时,当我打开文档是,总出现
Debug Error!
File:i386\chkesp.c
Line:42
The value of ESP was not properly saved across a function call. This is usually a result of calling a funtion declared with one calling convention with a function pointer declared with a different calling convention.
extern "C" __declspec(dllexport) int PrinterTest(int i)
{
return 0;
}调用程序
/////////////////////////////////////////////////////////////
typedef int (STDMETHODCALLTYPE * IC_Print)(int);
HINSTANCE gLib32_DLL;
IC_Print icprint;
gLib32_DLL = LoadLibrary ("CS.dll");
if (gLib32_DLL == NULL)
{
MessageBox("-1");
return;
}
//exit IC
icprint = (IC_Print) GetProcAddress (gLib32_DLL,"PrinterTest");
if (icprint == NULL)
{
FreeLibrary (gLib32_DLL);
MessageBox("-2");
}
else
MessageBox("0"); int ret = -1;
ret = icprint(1);
编译没问题,可是运行时,当我打开文档是,总出现
Debug Error!
File:i386\chkesp.c
Line:42
The value of ESP was not properly saved across a function call. This is usually a result of calling a funtion declared with one calling convention with a function pointer declared with a different calling convention.
解决方案 »
- 如何让WebBrowser弹出:此站点可能需要下列ActiveX控件:来自'aaaa'的'bbbbb软件'。单击此处安装...
- ICMP做的Ping 找错
- 满分求助用Sendmessage 修改 外部TreeView中的所选项Key 不是Text
- 怎样 关闭和打开 图形硬件加速? dxdiag
- 线程之间通信问题!
- DataGrid控件显示记录时,如何设置一行记录显示颜色(不是整个控件)
- Dll一定要DLLMAIN()函数吗?
- strstream
- 如何通过对象实例指针获得对象的结构?欢迎讨论!
- 一个socket套接字在建立一个连接并断开后,可不可以用原来的socket套接字再建立第二个连接?
- 老妈又催我快点找个女朋友,郁闷!散分!
- 在VS.net2003 中怎么产生CDocTemplate类
ret = icprint(1);
总出现帖子里错误
-----
extern "C" __declspec(dllexport) int PrinterTest(int i)
{
return 0;
}
----
但是你在调用时候使用的是__stdcall,
typedef int (STDMETHODCALLTYPE * IC_Print)(int);--------------------
这两种调用方式是不同的,上边的是函数结束的时候退栈,下边的是在调用的地方由调用者退栈,你的情况就是函数被退了2次栈,导致栈不平衡,肯定出错,
解决方法:统一dll和使用的地方的调用限定,最好在DLL中加上函数的调用限定。
{
return 0;
}对么
{
return 0;
}还是extern "C" (dllexport) int STDMETHODCALLTYPE PrinterTest(int i)
{
return 0;
}
typedef int (STDMETHODCALLTYPE * IC_Print)(int);
改为:
typedef int ( * IC_Print)(int);大家快点跟贴
准备散分