我不知道我的题目是否恰当.具体问题如下.已有(VC++)Add.dll
Add.h
__declspec(dllexport) int add(int x,int y)aDD.cpp
__declspec(dllexport) int add(int x,int y)
{
return x+y;
}然后在一个Com工程中调用 Add.dll 代码如下HINSTANCE hh=NULL;
hh=AfxLoadLibrary("Add.dll");
typeof int(*ADD)(int,int);
ADD add;
add=(ADD)GetProcAddress(hh,"add");
int z;
z=add(2,3);
当执行到 最后一句时就报错.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 function declared with one calling coneention with a function pointer declared with a different calling convention.

解决方案 »

  1.   

    这大概是你生成的dll的接口定义与你的调用程序不一致引起的堆栈越界,可以修改一下你的dll程序的编译设置,在project setting中的c/c++中的code generation里,将calling convention改为__stdcall试试
      

  2.   

    将typeof int(*ADD)(int,int);改为typedef int (__stdcall *ADD)(int, int);
      

  3.   

    楼上的朋友谢谢你的提示.
    我按照你的提示将.Add.dll中的函数声明前加上了 __stdCall 重新编译后问题解决了.但新的问题出现了.
    如果函数的返回类型是 char* 时不能在前面加上 __str
      

  4.   

    如果函数的返回类型是 char* 时不能在前面加上 __stdcall 
    我想知道char* 类型在标准调用时应该用什么类型代替.
      

  5.   

    谢谢楼上几位 问题解决了现在新的问题是如何在ActiveX工程中接收.dll函数返回的结构类型.
    是用typedef 定义一个吗?我试试.