VC2012升級補丁5.0之后,編譯出來的程序發現在XP系統無法定位程序輸入點 K32GetProcessMemoryInfo于動態鏈接庫kernel32.dll之上。
之前程序一直在XP上安裝正常,今天測試組的同事突然發現,新發布的版本不能在XP上使用,這個問題比較奇怪,因為以往的版本都是沒有問題的。為什么會突然出現這個問題呢?一開始就去查找是否所有工程都使用V110_XP來編譯,找完所有工程都沒出錯。最后才想到近來升級VC2012的Update5.0的補丁,再打包編譯之后,才發現XP的電腦不能使用了。
經過查找分析,發現是如下問題:
這是由于GetProcessMemoryInfo在不同系統版本號不同導致的,官方說明如下:
Remarks
Starting with Windows 7 and Windows Server 2008 R2, Psapi.h establishes version numbers for the PSAPI functions. The PSAPI version number affects the name used to call the function and the library that a program must load.
If PSAPI_VERSION is 2 or greater, this function is defined as K32GetProcessMemoryInfo in Psapi.h and exported in Kernel32.lib and Kernel32.dll. If PSAPI_VERSION is 1, this function is defined as GetProcessMemoryInfo in Psapi.h and exported in Psapi.lib and Psapi.dll as a wrapper that calls K32GetProcessMemoryInfo.
Programs that must run on earlier versions of Windows as well as Windows 7 and later versions should always call this function as GetProcessMemoryInfo. To ensure correct resolution of symbols, add Psapi.lib to the TARGETLIBS macro and compile the program with -DPSAPI_VERSION=1. To use run-time dynamic linking, load Psapi.dll.
解決方案如下:
只需要在#include <psapi.h>引用前添加
復制代碼 代碼如下:
#ifndef PSAPI_VERSION
#define PSAPI_VERSION 1
#endif
#include <psapi.h>
#pragma comment(lib,"Psapi.lib")
看來微軟已經不支持XP系統了,因此所有發布的新版本軟件已經不再測試XP的兼容性了。看來明年,也需要轉向不支持XP系統了,否則需要投入的測試成本和維護成本急劇上升中,需要全面轉向WIN7和WIN10系統的支持。有此可見,生態系統就是這么重要的事情,可以左右大局。
新聞熱點
疑難解答