VC调用动态链接库的错误

来源:互联网 发布:约爱是什么软件 编辑:程序博客网 时间:2024/05/21 07:33


VC调用动态链接库的错误(Run-Time Check Failure #0

 (2009-05-27 11:26:26)
转载
标签: 

杂谈

分类: 学习记录

今天在网上看了一个杀进程的程序,复制过来编译,结果执行完后报错:Run-Time Check Failure #0   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 calling convention.

想了很久还是不知道错误,于是上网查,我要调用的动态库里的函数是远C函数,所以在函数指针定义是要如下格式:

 也就是在函数指针前面加上__stdcall就可以了。

typedef int (__stdcall*lpE_Pro_KillProcessByName)(IN const char* pchar_param_ProName);

HINSTANCE hDll; //DLL句柄
    lpE_Pro_KillProcessByName KillProcessByName;
    hDll = LoadLibrary("WinAPIExS.dll");
    if (hDll != NULL)
    {
     KillProcessByName=(lpE_Pro_KillProcessByName)GetProcAddress(hDll, "E_Pro_KillProcessByName");
     if (KillProcessByName != NULL)
     {
      const char procname[]="Thunder5.exe";
      KillProcessByName(procname);
     }
     FreeLibrary(hDll);
    }

0 0