我用w32编写的dll
extern "C" __declspec (dllexport)  int test (int a) 
{
    return a;
}
在调用的时候出错,请问是什么原因?
HINSTANCE m_hDLL=LoadLibrary("w32dll.dll");
typedef int (CALLBACK* LPTEST)(int);
LPTEST test;
if(m_hDLL!=NULL)
{
  test=(LPTEST)GetProcAddress(m_hDLL,"test");
  int ok=test(2);
}

解决方案 »

  1.   

    返回的是值,应该没问题。不然改成
    extern "C" __declspec (dllexport)  int test (int a) 
    {
        int ret =a; 
        return ret ;
    }试试。
    对了你没说“调用时出错”是错在哪儿了?
      

  2.   

    在debug下调试,运行到 int  ok=test(2);  
    时,提示:出错信息
    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 
    convention
    谢谢帮忙看看!
      

  3.   

    如果不带参数的话,比如void返回一个对话框,我国是没有问题的,
    不知为啥代参数后就出错了???
    请帮忙看看看,非常感谢!!!
      

  4.   

    哎!没有老兄愿意帮忙??
    我还是自己解决吧!!
    我查阅了以前的贴子,解决了!
    由参数不用CALLBACK
      

  5.   

    看你的提示信息,应该是调用约定不匹配造成的。
    c的默认调用约定是_cdecl,你声明函数时用上stdcall:extern "C" __declspec (dllexport) int __stdcall test (int a) 
    {
        return a;
    }注意在函数定义和声明两个地方都加上__stdcall再试试。