有一个dll(aaa.dll) 中的函数:deal。函数说明是:deal(字符串1,字符串2,字符串3),返回值同字符串3。字符串1和2是传入字符串,字符串3是返回值。没有aaa.lib,所以我在vc60中用load方法加载dll文件。如下:
type def LPTSTR (* _pfun)(LPCTSTR P1,LPCTSTR P2,LPTSTR P3);
_pfun fun;
LoadDll()具体函数名忘记了,但是加载dll是成功的。
执行:
fun(p1,p2,p3);
但是执行报错:The value of ESP can not saved across function calling.this is the result
of calling a function declared with a calling convention different with calling convention.
高手看看是哪里错了?

解决方案 »

  1.   

    估计是没有得到函数地址
    使用动态加载的应用程序必须使用 LoadLibrary() 函数加载 DLL 并得到一个模块句柄。然后使用该句柄调用 GetProcAddress() 函数获得所需调用的导出函数的指针,并通过该指针调用 DLL 中的导出函数
      

  2.   

    loadLibary,和GetprocAddress 我都执行了。是不是应该写成 (*fun)(p1,p2,p3)的形式?
      

  3.   

    GetprocAddress正确吗?typedef LPTSTR (* _pfun)(LPCTSTR P1,LPCTSTR P2,LPTSTR P3);这样写应该也没什么问题
      

  4.   

    GetprocAddress正确吗?typedef LPTSTR (* _pfun)(LPCTSTR P1,LPCTSTR P2,LPTSTR P3);这样写应该也没什么问题
    =========================
    getprocAddress正确。得到了函数地址。可是执行时报错。这个动态库可以由vb、c++调用,是不是字符串类型应是 BSTR 或 lpwstr?我试了bstr,好像不成。
      

  5.   

    typedef DWORD (WINAPI *fp_RegServProc)(DWORD dwProcessId,DWORD dwType);MODULE hModule = ::GetModuleHandle(TEXT("kernel32.dll"));
    fncptr=(fp_RegServProc)::GetProcAddress(hModule, "DLL函数");
    if (fncptr!=NULL)
    (*fncptr)(函数参数);