解決Qt發佈的程序在xp環境下提示「沒法定位程序輸入點 K32GetModuleFileNameExA 於動態連接庫 KERNEL32.dll 上」的錯誤

Qt開發時,調用系統API函數時的問題,在win7及以上系統沒什麼大問題。在xp下出現了標題描述的現象,致使沒法啓動程序。看了下網上的解決方案以下:api

 

 

這裏我要討論的是在 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中根本沒有那些被移植過去的函數,因此確定會執行失敗。

受影響的函數以下:app

  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
#endifspa

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

 

至此能夠解決問題,注意紅色字體部分,開始只加了上半部分,直接編譯異常,把後面一行紅色部分加入後才能夠。剛開始涉足Qt,碰到的問題網上大都能解決,該問題列出供本身參考。orm

相關文章
相關標籤/搜索