来自 PowrProf.h 的 CallNtPowerInformation 的新项目有链接器错误
Fresh Project With CallNtPowerInformation From PowrProf.h Having Linker Errors
我刚刚在 visual studio 2017 RC 中创建了一个新项目(Win32 控制台应用程序),并对其进行了编码,据我所知,它应该可以工作。
#include "stdafx.h"
#include <string>
#include <iostream>
#include <windows.h>
#include "PowrProf.h Or Powerbase.h"
using namespace std;
int main(int argc, _TCHAR* argv[])
{
SYSTEM_POWER_POLICY PowerPlugged;
SYSTEM_POWER_POLICY PowerUnPlugged;
POWER_ACTION_POLICY ActionPlugged;
POWER_ACTION_POLICY ActionUnPlugged;
CallNtPowerInformation(SystemPowerPolicyAc, NULL, 0, &PowerPlugged, sizeof(SYSTEM_POWER_POLICY));
CallNtPowerInformation(SystemPowerPolicyDc, NULL, 0, &PowerUnPlugged, sizeof(SYSTEM_POWER_POLICY));
ActionPlugged.Action = PowerActionNone;
ActionUnPlugged.Action = PowerActionNone;
PowerPlugged.LidClose = ActionPlugged;
PowerUnPlugged.LidClose = ActionUnPlugged;
CallNtPowerInformation(SystemPowerPolicyAc, &PowerPlugged, sizeof(SYSTEM_POWER_POLICY), NULL, 0);
CallNtPowerInformation(SystemPowerPolicyDc, &PowerUnPlugged, sizeof(SYSTEM_POWER_POLICY), NULL, 0);
string yaes;
getline(cin, yaes);
return 0;
}
如果这是一个愚蠢的问题,我很抱歉,但我真的从来没有处理过链接器,而且代码没有给我任何错误。当然建筑时除外。
documentation 的备注部分对此没有任何说明。
我在 windows 10,我已经尝试包括 Powerbase.h、PowrProf.h。两者都给了我完全相同的错误:
LNK2019: unresolved external symbol _CallNtPowerInformation@20
referenced in function
_main BatterySettings c:\Users\badmouthing\documents\visual studio
2017\Projects\BatterySettings\BatterySettings\BatterySettings.obj
当然
LNK1120 1 unresolved externals BatterySettings c:\users\profanity(I'm
just having fun, the username is the same)\documents\visual studio
2017\Projects\BatterySettings\Debug\BatterySettings.exe
那我做错了什么?
谢谢。
当您包含 PowrProf.h 时,尝试这样做
extern "C" {
#include <Powrprof.h>
}
#pragma comment(lib, "Powrprof.lib")
如果不是这样,您是否尝试过进行干净重建?
我刚刚在 visual studio 2017 RC 中创建了一个新项目(Win32 控制台应用程序),并对其进行了编码,据我所知,它应该可以工作。
#include "stdafx.h"
#include <string>
#include <iostream>
#include <windows.h>
#include "PowrProf.h Or Powerbase.h"
using namespace std;
int main(int argc, _TCHAR* argv[])
{
SYSTEM_POWER_POLICY PowerPlugged;
SYSTEM_POWER_POLICY PowerUnPlugged;
POWER_ACTION_POLICY ActionPlugged;
POWER_ACTION_POLICY ActionUnPlugged;
CallNtPowerInformation(SystemPowerPolicyAc, NULL, 0, &PowerPlugged, sizeof(SYSTEM_POWER_POLICY));
CallNtPowerInformation(SystemPowerPolicyDc, NULL, 0, &PowerUnPlugged, sizeof(SYSTEM_POWER_POLICY));
ActionPlugged.Action = PowerActionNone;
ActionUnPlugged.Action = PowerActionNone;
PowerPlugged.LidClose = ActionPlugged;
PowerUnPlugged.LidClose = ActionUnPlugged;
CallNtPowerInformation(SystemPowerPolicyAc, &PowerPlugged, sizeof(SYSTEM_POWER_POLICY), NULL, 0);
CallNtPowerInformation(SystemPowerPolicyDc, &PowerUnPlugged, sizeof(SYSTEM_POWER_POLICY), NULL, 0);
string yaes;
getline(cin, yaes);
return 0;
}
如果这是一个愚蠢的问题,我很抱歉,但我真的从来没有处理过链接器,而且代码没有给我任何错误。当然建筑时除外。
documentation 的备注部分对此没有任何说明。
我在 windows 10,我已经尝试包括 Powerbase.h、PowrProf.h。两者都给了我完全相同的错误:
LNK2019: unresolved external symbol _CallNtPowerInformation@20 referenced in function _main BatterySettings c:\Users\badmouthing\documents\visual studio 2017\Projects\BatterySettings\BatterySettings\BatterySettings.obj
当然
LNK1120 1 unresolved externals BatterySettings c:\users\profanity(I'm just having fun, the username is the same)\documents\visual studio 2017\Projects\BatterySettings\Debug\BatterySettings.exe
那我做错了什么? 谢谢。
当您包含 PowrProf.h 时,尝试这样做
extern "C" {
#include <Powrprof.h>
}
#pragma comment(lib, "Powrprof.lib")
如果不是这样,您是否尝试过进行干净重建?