解決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,碰到的問題網上大都能解決,該問題列出供自己參考。


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM