c++ - 来自 PowrProf.h 的 CallNtPowerInformation 的新项目有链接器错误

标签 c++ winapi 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")

如果不是这样,您是否尝试过进行干净的重建?

关于c++ - 来自 PowrProf.h 的 CallNtPowerInformation 的新项目有链接器错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41978314/

相关文章:

c++ - OGL ESv2 中的同一游戏不适用于 OGL3

windows - Windows "interface names"是什么样子的?

c++ - Windows 中的 clang "hello, world!"链接错误

c++ - 从 C++ 包装器调用导出的 C 函数时出现错误 LNK2028

ipad - 架构 i386 :Apple Mach-O Linke(id)error 的 undefined symbol

C++ 符号在共享对象中具有不同的大小

c++ - Pimpl 习语和没有友元声明的内部对象协作

c++ - 将结构数组传递给内核会导致写入时出现段错误?

c - Win32 剪贴板和 alpha channel 图像

c++ - 制作分组框按钮 win32 C++