运行时检查失败#0从kernel32.dll加载QueryFullProcessImageName [英] Run-Time Check Failure #0 loading QueryFullProcessImageName from kernel32.dll

查看:515
本文介绍了运行时检查失败#0从kernel32.dll加载QueryFullProcessImageName的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个应用程序需要在WinXP和Vista64上运行。我的程序需要QueryFullProcessImageName()在Vista上而不是在XP上。



我尝试通过kernel32.dll加载QueryFullProcessImageName()相同的可执行文件可以在WinXP和Vista上运行。加载它的代码是:

  //仅在vista上调用
bool LoadQueryFullProcessImageName()
{
HMODULE hDLL = LoadLibrary(kernel32.dll);
if(!hDLL)return(0);

//现在使用指针访问DLL中定义的函数
fpQueryFullProcessImageName =(LPQueryFullProcessImageName)GetProcAddress(hDLL,QueryFullProcessImageNameA); // ANSI version
if(!fpQueryFullProcessImageName)
return false;

return true;
}

typedef

  typedef WINBASEAPI 
BOOL(* LPQueryFullProcessImageName)(
__in HANDLE hProcess,
__in DWORD dwFlags,
__out_ecount_part(* lpdwSize,* lpdwSize )LPSTR lpExeName,
__inout PDWORD lpdwSize
);不幸的是,我在Vista上得到一个运行时错误,当函数指针被取消引用时:



运行时检查失败#0 - ESP的值在函数调用中未正确保存。这通常是使用一个调用约定声明的函数调用以不同调用约定声明的函数指针的结果。



typedef直接从.h文件我不明白为什么它搞砸了。任何帮助?我试过吨变种,但没有运气。

解决方案

您应该将typedef更改为

  typedef BOOL(WINAPI * LPQueryFullProcessImageName)(
HANDLE hProcess,DWORD dwFlags,LPSTR lpExeName,PDWORD lpdwSize);

WINBASEAPI用于声明静态依赖项,并且不指定__stdcall调用约定。你使用GetProcAddress(),所以静态依赖对你没有兴趣,但你仍然需要__stdcall适当的调用调用。


I have an application that needs to run both on WinXP and Vista64. My program requires QueryFullProcessImageName() to work on Vista but not on XP.

I try to load QueryFullProcessImageName() (instead of linking statically) via the kernel32.dll so that the same executable can run on both WinXP and Vista. The code that loads it is:

//only gets called on vista
bool LoadQueryFullProcessImageName()
{
  HMODULE hDLL = LoadLibrary("kernel32.dll");
  if (!hDLL) return(0);

  //Now use pointer to get access to functions defined in DLL
  fpQueryFullProcessImageName = (LPQueryFullProcessImageName)GetProcAddress(hDLL, "QueryFullProcessImageNameA"); //ANSI version
  if (!fpQueryFullProcessImageName) 
     return false;

  return true;
}

the typedef is

typedef WINBASEAPI
BOOL (*LPQueryFullProcessImageName)(
    __in HANDLE hProcess,
    __in DWORD dwFlags,
    __out_ecount_part(*lpdwSize, *lpdwSize) LPSTR lpExeName,
    __inout PDWORD lpdwSize
    );

Unfortunately, I get a run time error on Vista when the function pointer is dereferenced:

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.

The typedef is straight from the .h file so I can't understand why it's messing up. Any help? I've tried tons of variants but no luck.

解决方案

You should change the typedef to

typedef BOOL (WINAPI *LPQueryFullProcessImageName)(
     HANDLE hProcess, DWORD dwFlags, LPSTR lpExeName, PDWORD lpdwSize );

WINBASEAPI is used for declaring static dependencies and it doesn't specify the __stdcall calling convention. You use GetProcAddress() and so the static dependency is of no interest to you, but you still need __stdcall for proper call invokation.

这篇关于运行时检查失败#0从kernel32.dll加载QueryFullProcessImageName的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆