无法定位程序输入点 K32GetProcessMemoryInfo于动态链接库kernel32.dll之上

本文详细解释了在不同Windows系统版本中使用GetProcessMemoryInfo函数时遇到的问题,以及如何通过修改代码来确保函数在各种环境下正确运行。通过在引用psapi.h之前添加预处理器指令,确保程序能够在早期Windows版本和较新版本之间无缝工作。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

这是由于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")

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值