//testDll.h
WINAPI int testDll(int a,int b);//testDll.def
EXPORTS      
testDll @1//testDll.cpp
#include <windows.h>WINAPI int testDll(int a,int b){ 
char mess[512]; HMODULE hDllModule;             //&Ouml;&cedil;&Iuml;ò&para;&macr;&Igrave;&not;&iquest;&acirc;&micro;&Auml;&frac34;&auml;±ú
int ret;
ret = 0;
int (* start_gprs_server)(HWND,int,int,char *);  //&para;¨&Ograve;&aring;&Ograve;&raquo;&cedil;&ouml;&Ouml;&cedil;&Iuml;ò&ordm;&macr;&Ecirc;&yacute;&micro;&Auml;&micro;&Oslash;&Ouml;·&micro;&Auml;&Ouml;&cedil;&Otilde;&euml;
ret = 1;
hDllModule=LoadLibrary("gprs_dll.dll");
ret = 2;
if (hDllModule!=NULL)    //&Aring;&ETH;&para;&Iuml;&micro;÷&Oacute;&Atilde;&Ecirc;&Ccedil;·&ntilde;&sup3;&Eacute;&sup1;&brvbar;
{
       //&acute;&Oacute;&para;&macr;&Igrave;&not;&iquest;&acirc;&Ouml;&ETH;&Egrave;&iexcl;&ordm;&macr;&Ecirc;&yacute;&micro;&Oslash;&Ouml;·
       start_gprs_server = (int (*)(HWND,int,int,char *))GetProcAddress(hDllModule,"start_gprs_server");
       ret = 3;
   if (start_gprs_server !=NULL)   //&Aring;&ETH;&para;&Iuml;&Ecirc;&Ccedil;·&ntilde;&Egrave;&iexcl;&micro;&frac12;&cedil;&Atilde;&ordm;&macr;&Ecirc;&yacute;&micro;&Oslash;&Ouml;·
        {
//&iquest;&Eacute;&Ograve;&Ocirc;&Iuml;&Egrave;&Eacute;è&para;¨&sup1;¤×÷&Auml;&pound;&Ecirc;&frac12;
            //SetWorkMode(1) //0;1;2
   ret = 4;
           ret = ret + (*start_gprs_server)(NULL,123,5002,mess);
ret = 5;
        }
}

return (a+b);}
运行到(*start_gprs_server)(NULL,123,5002,mess);
总是出错。
提示:
The value of ESP was not a properly saved accross a function call。This is usually a result
of calling a function declared with one calling convention with a function poiter 
declared with a different  calling convention 。有方法可以解决?

解决方案 »

  1.   

    晕,不要贴乱码.typedef int (WINAPI STARTSERVER)(HWND,int,int,char *);STARTSERVER* start_gprs_server  = NULL;
    WINAPI int testDll(int a,int b)

    //前面都一样
    start_gprs_server  = (STARTSERVER*)GetProcAddress(hDllModule,"start_gprs_server");
    }
          
      

  2.   

    我遇到过,你是不是调用了DLL了??
    这个问题是因为堆栈指针不平衡,可能是函数退出的时候没有恢复堆栈导致的,上次我出现这问题的解决办法有两个:
    一个是_asm{sub 4;(根据实际情况而定)};内嵌汇编,自己使堆栈平衡;
    二是明白你使用函数的堆栈平衡机制,_stdcall约定还是_cdecl约定,然后和你的编译器调用约定一样就行了.一般在VC++6下,找到出错函数,声明为:extern "C" 返回值 _stdcall 函数名 (参数);就解决问题了.
      

  3.   

    谢谢各位,问题已经解决,需要在定义的时候指明使用函数的堆栈平衡机制。
    如 EnochShen(小疯子:真的好菜—知耻而后勇!) 和 BigFanOfCpp(((Bytes)+_ALGIN-1) & ~(_ALGIN-1)) 所述