zoukankan      html  css  js  c++  java
  • 解决Qt发布的程序在xp环境下提示“无法定位程序输入点 K32GetModuleFileNameExA 于动态链接库 KERNEL32.dll 上”的错误

    Qt开发时,调用系统API函数时的问题,在win7及以上系统没什么大问题。在xp下出现了标题描述的现象,导致无法启动程序。看了下网上的解决方案如下:

    这里我要讨论的是在 WinSDK v7.0中的一些不友好的错误。如果你是一名开发者,并且当前使用的是VS2010编译器自带的 WinSDK v7.0,那么个别时候当你执行程序时,可能遇到这样的错误提示:The procedure entry point K32*** could not be located in the dynamic link library KERNEL32.dll
    中文版本的就是:无法定位程序输入点K32EnumProcessModules于动态链接库KERNEL32.dll上。这样的错误提示一般会出现在非 Windows7 或者 Windows Server 2008 R2 的系统上面。

    下面我解释下为什么会出现这样的错误。因为一些性能的问题,在Windows7 和 Windows Server 2008 R2 系统上,微软把一些API函数从Psapi.dll 移到了 Kernel32.dll 动态库中,并在VS2010编译器自带的 WinSDK v7.0版本上面做了处理。这样的设计在Windows7 和 Windows Server 2008 R2系统上面没有问题,但是如果你用vs2010编译的程序运行在Win7之前的系统上,那么肯定会遇到刚才说的错误。因为老系统的KERNEL32.dll中根本没有那些被移植过去的函数,所以肯定会执行失败。

    受影响的函数如下:

    1. //Snapshot from Psapi.lib – WinSDK V7.0*
    2. #if (PSAPI_VERSION > 1)
    3. #define EnumProcesses               K32EnumProcesses
    4. #define EnumProcessModules          K32EnumProcessModules
    5. #define EnumProcessModulesEx        K32EnumProcessModulesEx
    6. #define GetModuleBaseNameA          K32GetModuleBaseNameA
    7. #define GetModuleBaseNameW          K32GetModuleBaseNameW
    8. #define GetModuleFileNameExA        K32GetModuleFileNameExA
    9. #define GetModuleFileNameExW        K32GetModuleFileNameExW
    10. #define GetModuleInformation        K32GetModuleInformation
    11. #define EmptyWorkingSet             K32EmptyWorkingSet
    12. #define QueryWorkingSet             K32QueryWorkingSet
    13. #define QueryWorkingSetEx           K32QueryWorkingSetEx
    14. #define InitializeProcessForWsWatch K32InitializeProcessForWsWatch
    15. #define GetWsChanges                K32GetWsChanges
    16. #define GetWsChangesEx              K32GetWsChangesEx
    17. #define GetMappedFileNameW          K32GetMappedFileNameW
    18. #define GetMappedFileNameA          K32GetMappedFileNameA
    19. #define EnumDeviceDrivers           K32EnumDeviceDrivers
    20. #define GetDeviceDriverBaseNameA    K32GetDeviceDriverBaseNameA
    21. #define GetDeviceDriverBaseNameW    K32GetDeviceDriverBaseNameW
    22. #define GetDeviceDriverFileNameA    K32GetDeviceDriverFileNameA
    23. #define GetDeviceDriverFileNameW    K32GetDeviceDriverFileNameW
    24. #define GetProcessMemoryInfo        K32GetProcessMemoryInfo
    25. #define GetPerformanceInfo          K32GetPerformanceInfo
    26. #define EnumPageFilesW              K32EnumPageFilesW
    27. #define EnumPageFilesA              K32EnumPageFilesA
    28. #define GetProcessImageFileNameA    K32GetProcessImageFileNameA
    29. #define GetProcessImageFileNameW    K32GetProcessImageFileNameW
    30. #endif

    复制代码

    通过上面的解释,你应该明白为什么出现那样的错误了吧?也大体上知道怎么样改正这个错误了。不知道大家注意到没有,有个条件判断#if (PSAPI_VERSION > 1),也就是说只有当PSAPI_VERSION被定义为大于1的数值时才有这样的问题,所以解决方案就是将 PSAPI_VERSION 定义为小于等于1的数值就可以啦,如下:

    要加在#include <Psapi.h>上面

    #ifndef PSAPI_VERSION
    #define PSAPI_VERSION  1
    #endif

    #include <Tlhelp32.h>
    #include <Psapi.h>
    #pragma comment(lib, "Psapi.lib")

    至此可以解决问题,注意红色字体部分,开始只加了上半部分,直接编译异常,把后面一行红色部分加入后才可以。刚开始涉足Qt,碰到的问题网上大都能解决,该问题列出供自己参考。

  • 相关阅读:
    selenium 定位元素的基本方法(6)
    selenium ,先了解html 基础知识(5)
    第 39 章 ThinkPHP--SQL 连贯操作
    第 39 章 ThinkPHP--模型初步(下)
    第 39 章 ThinkPHP--模型初步
    第 39 章 ThinkPHP--模块化和 URL 模式
    CSS属性编写顺序
    Ajax_使用jQuery 实现Ajax
    Ajax_数据格式三大类
    Ajax_使用XMLHttpRequest实现
  • 原文地址:https://www.cnblogs.com/acmexyz/p/8521843.html
Copyright © 2011-2022 走看看