2017-02-01 28 views
1

Visual Studio 2017 RCで新しいプロジェクト(Win32コンソールアプリケーション)を作成しましたが、これをコード化しています。CallNtPowerInformationを使用したFresh Projectリンカエラーがある場合

#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:プロジェクト\ BatterySettings \ BatterySettings \ BatterySettings \ Visual Studioの 2017 \ \ドキュメントをbadmouthing \ \ユーザー:20個の 機能で参照 _main BatterySettingsのC @未解決の外部シンボル_CallNtPowerInformationはどちらも私にまったく同じエラーを与えました.objファイル

そしてもちろんの

LNK1120 1個の未解決の外部のBatterySettingsのC:\ Users \ユーザー冒涜(私はよはただのVisual Studio \ \ドキュメント 2017は、だから私は間違って何をやっている

プロジェクト\ BatterySettings \デバッグ\ BatterySettings.exe \)楽しんで、ユーザ名が同じですか? ありがとうございます。

答えて

3

あなたはPowrProf.hこの

extern "C" { 
#include <Powrprof.h> 

} 
#pragma comment(lib, "Powrprof.lib") 

ようにそれをやってみ含めることがない場合は、再構築クリーンをやってみましたか?

+0

Worked。どうやって説明するの? – TrisT

+0

正直に分かりませんが、私は[ここ](https://groups.google.com/forum/#!topic/microsoft.public.win32.programmer.kernel/7EEgNku48W8)と[ここ](http: //www.yqcomputer.com/76_3274_1.htm) – ninjaiceflame

+1

@ninjaiceflame - あなたは['CallNtPowerInformation'](https://msdn.microsoft.com/en-us/library/windows/desktop/aa372675(v = vs。 85).aspx) - だからどこかで実装する必要があります。 'PowrProf.dll'に実装されているドキュメントを読んだら、' PowrProf.lib'とのリンクが必要です。 – RbMm

関連する問題