GetModuleFileNameEx遍历获取64bit程序路径失败的一种解决方法(Win7-64-bit)

问题:

32位程序在64位系统上调用GetModuleFileNameEx()遍历获取64位进程的全路径失败,得到的路径都为空。


根据官方的说法:

For the best results use the following table to convert paths.

Windows 2000 = GetModuleFileNameEx()
Windows XP x32 = GetProcessImageFileName()
Windows XP x64 = GetProcessImageFileName()
Windows Server2003  = GetProcessImageFileName()
Windows Vista = QueryFullProcessImageName()
Windows 7 = QueryFullProcessImageName()


Note: If you are not aware the API GetProcessImageFileName() returns a kernel DOS device path. You can use the following API to map the device paths to a Win32 format.

但要注意的是GetModuleFileName在64bit下获取到的是不正确的,用32去填充64结果是空。

本人在32bit的win7下可以准确获取,64bit的win7下得不到自己要的东西。如下图所示:




推荐用vista新增的:QueryFullProcessImageName(),结果入下图:



另外搜遍了网络也没搜到该函数的样例,再懒也只好自己写了~~

DWORD size = MAX_PATH;
char sExeName[MAX_PATH] = {0};
QueryFullProcessImageName(hProcess, 0, sExeName, &size);
当然用GetProcessImageFileName获取更好,只是代码有点长,懒的写了。


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值