第一种:
__declspec(dllexport) int __stdcall myfunction(int a,int b)
{
return 1;
}
第二种:
__declspec(dllexport) int myfunction(int a,int b)
{
return 1;
}
然后在工程设置的C/C++选项卡设Code Generation为__stdcall.第三种:
int __stdcall myfunction(int a,int b)
{
return 1;
}
然后在.def文件中加上myfunction。我发现第三种可以正常调用,但第一、二种根本就找不到这个函数。
另外,如果dll导出的时候用的是__stdcall,但我用VC调用的时候,默认为__cdecl,那么我怎样才能以__stdcall的方式调用这些函数呢(用动态加载的方式)?
望指点。

解决方案 »

  1.   

    定义一个函数指针类型typedef __stdcall int (*LPLoadResString)(UINT,TCHAR*,int);LPLoadResString myfun;
    HANDLE m_ResDll;
    m_ResDll=LoadLibrary("eresdll.dll");
    myfun=(LPLoadResString)GetProcAddress(m_ResDll,"LoadResMenu");
      

  2.   

    调用函数
    myfun(1,(TCAHR*)"test",12);
      

  3.   

    我用如下的代码来试验:
    typedef __stdcall int  (*proc)(
         SQLHWND,
         SQLCHAR *,
         SQLSMALLINT,
         SQLSMALLINT * ,
         SQLUSMALLINT);proc pfn;
    pfn=(proc)GetProcAddress(hdll,"PbDriverConnect");结果有以下一大堆错:D:\Project\testdll2\testdll2View.cpp(114) : error C2629: unexpected 'int ('
    D:\Project\testdll2\testdll2View.cpp(121) : error C2065: 'proc' : undeclared identifier
    D:\Project\testdll2\testdll2View.cpp(121) : error C2146: syntax error : missing ';' before identifier 'pfn'
    D:\Project\testdll2\testdll2View.cpp(121) : error C2065: 'pfn' : undeclared identifier
    D:\Project\testdll2\testdll2View.cpp(122) : error C2146: syntax error : missing ';' before identifier 'GetProcAddress'
    Error executing cl.exe.testdll2.exe - 5 error(s), 0 warning(s)
      

  4.   

    extern "C" __declspec(dllexport) int __stdcall myfunction(int a,int b)在.def文件中键入:
    EXPORTS
       myfunction   @1
      

  5.   

    to lwg7603():
    如果不在.def文件中加入那些东西,难道就不行吗?因为我已经声明是导出函数的了。
      

  6.   

    typedef __stdcall int (*LPLoadResString)(UINT,TCHAR*,int);错了typedef int __stdcall (*LPLoadResString)(UINT,TCHAR*,int);
      

  7.   

    不知道你的是什么工程~?
    __declspec(dllexport)
    好像是MFC的东西~如果我没弄错的话~
    我手头没有MSDN~
    无法考证~
      

  8.   

    __stdcall 的东西总是要被Mangle的,所以你用正常方法看不到.建议你试一试这个:
    #pragma comment(linker, "/export:myfunction=_myfunction@8");
    // 方在CPP文件里就行了.