运行时检查失败 #0 从 kernel32.dll 加载 QueryFullPro

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

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

问题描述

我有一个应用程序需要在 WinXP 和 Vista64 上运行.我的程序需要 QueryFullProcessImageName() 才能在 Vista 上运行,但不能在 XP 上运行.

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.

我尝试通过 kernel32.dll 加载 QueryFullProcessImageName()(而不是静态链接),以便相同的可执行文件可以在 WinXP 和 Vista 上运行.加载它的代码是:

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;
}

typedef 是

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

不幸的是,当函数指针被取消引用时,我在 Vista 上遇到运行时错误:

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

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

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.

typedef 直接来自 .h 文件,所以我不明白为什么它搞砸了.有什么帮助吗?我已经尝试了大量的变体,但没有运气.

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.

推荐答案

您应该将 typedef 更改为

You should change the typedef to

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

WINBASEAPI 用于声明静态依赖项,它不指定 __stdcall 调用约定.您使用 GetProcAddress(),因此您对静态依赖项不感兴趣,但您仍然需要 __stdcall 以进行正确的调用.

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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本文标题为:运行时检查失败 #0 从 kernel32.dll 加载 QueryFullPro

基础教程推荐