Run-Time Check Failure #0 loading QueryFullProcessImageName from kernel32.dll(运行时检查失败 #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
基础教程推荐
- 如何在不破坏 vtbl 的情况下做相当于 memset(this, ...) 的操作? 2022-01-01
- 使用从字符串中提取的参数调用函数 2022-01-01
- 为什么语句不能出现在命名空间范围内? 2021-01-01
- 如何使图像调整大小以在 Qt 中缩放? 2021-01-01
- 管理共享内存应该分配多少内存?(助推) 2022-12-07
- 为 C/C++ 中的项目的 makefile 生成依赖项 2022-01-01
- Windows Media Foundation 录制音频 2021-01-01
- 如何“在 Finder 中显示"或“在资源管理器中显 2021-01-01
- 从 std::cin 读取密码 2021-01-01
- 在 C++ 中循环遍历所有 Lua 全局变量 2021-01-01