13,825
社区成员
发帖
与我相关
我的任务
分享
#include <vcl.h>
#include <powrprof.h>
#pragma link "C:\\Program Files\\Borland\\CBuilder6\\Lib\\powrprof.lib"
#pragma hdrstop
#include "Unit1.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
}
//---------------------------------------------------------------------------
DWORD WINAPI PowerDuplicateScheme( __in_opt HKEY RootPowerKey, __in const GUID *SourceSchemeGuid, __in GUID **DestinationSchemeGuid );
void __fastcall TForm1::Button1Click(TObject *Sender)
{
WCHAR displayBuffer[_MAX_PATH] = L"超级节能";
DWORD displayBufferSize = _MAX_PATH;
GUID *GUID_HIGH_POWERSAVE = NULL;
if(ERROR_SUCCESS == PowerDuplicateScheme(NULL,&GUID_BALANCED,&GUID_HIGH_POWERSAVE))
{
ShowMessage("DuplicateScheme ok");
}
}
//---------------------------------------------------------------------------
麻烦再看一下。想先研究好静态调用。我已经通过implib生成lib
现在还是报一堆错:
[C++ Error] Unit1.cpp(20): E2451 Undefined symbol '__in_opt'
[C++ Error] Unit1.cpp(20): E2293 ) expected
[C++ Error] Unit1.cpp(26): E2451 Undefined symbol 'GUID_BALANCED'
[C++ Error] Unit1.cpp(26): E2314 Call of nonfunction
[C++ Warning] Unit1.cpp(30): W8004 'GUID_HIGH_POWERSAVE' is assigned a value that is never used
[C++ Warning] Unit1.cpp(30): W8004 'displayBufferSize' is assigned a value that is never used
[C++ Warning] Unit1.cpp(30): W8004 'displayBuffer' is assigned a value that is never used
#include <powrprof.h>
#include <vcl.h>
#pragma hdrstop
#include "Unit1.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
}
//---------------------------------------------------------------------------
DWORD WINAPI PowerDuplicateScheme( __in_opt HKEY RootPowerKey, __in const GUID *SourceSchemeGuid, __in GUID **DestinationSchemeGuid );
void __fastcall TForm1::Button1Click(TObject *Sender)
{
WCHAR displayBuffer[_MAX_PATH] = L"超级节能";
DWORD displayBufferSize = _MAX_PATH;
GUID *GUID_HIGH_POWERSAVE = NULL;
if(ERROR_SUCCESS == PowerDuplicateScheme(NULL,&GUID_BALANCED,&GUID_HIGH_POWERSAVE))
{
MessageBox("DuplicateScheme ok");
}
}
然后报了一堆错误:
[C++ Error] powrprof.h(37): E2303 Type name expected
[C++ Error] powrprof.h(37): E2139 Declaration missing ;
[C++ Error] powrprof.h(38): E2303 Type name expected
[C++ Error] powrprof.h(38): E2139 Declaration missing ;
[C++ Error] powrprof.h(39): E2303 Type name expected
[C++ Error] powrprof.h(39): E2238 Multiple declaration for '_GLOBAL_MACHINE_POWER_POLICY::SYSTEM_POWER_STATE'
[C++ Error] powrprof.h(38): E2344 Earlier declaration of '_GLOBAL_MACHINE_POWER_POLICY::SYSTEM_POWER_STATE'
[C++ Error] powrprof.h(39): E2139 Declaration missing ;
[C++ Error] powrprof.h(40): E2303 Type name expected
[C++ Error] powrprof.h(40): E2238 Multiple declaration for '_GLOBAL_MACHINE_POWER_POLICY::ULONG'
[C++ Error] powrprof.h(37): E2344 Earlier declaration of '_GLOBAL_MACHINE_POWER_POLICY::ULONG'
[C++ Error] powrprof.h(40): E2139 Declaration missing ;
[C++ Error] powrprof.h(44): E2303 Type name expected
[C++ Error] powrprof.h(44): E2139 Declaration missing ;
[C++ Error] powrprof.h(45): E2303 Type name expected
[C++ Error] powrprof.h(45): E2139 Declaration missing ;
[C++ Error] powrprof.h(46): E2303 Type name expected
[C++ Error] powrprof.h(46): E2238 Multiple declaration for '_GLOBAL_USER_POWER_POLICY::POWER_ACTION_POLICY'
[C++ Error] powrprof.h(45): E2344 Earlier declaration of '_GLOBAL_USER_POWER_POLICY::POWER_ACTION_POLICY'
[C++ Error] powrprof.h(46): E2139 Declaration missing ;
[C++ Error] powrprof.h(47): E2303 Type name expected
[C++ Error] powrprof.h(47): E2238 Multiple declaration for '_GLOBAL_USER_POWER_POLICY::POWER_ACTION_POLICY'
[C++ Error] powrprof.h(46): E2344 Earlier declaration of '_GLOBAL_USER_POWER_POLICY::POWER_ACTION_POLICY'
[C++ Error] powrprof.h(47): E2139 Declaration missing ;
[C++ Error] powrprof.h(48): E2303 Type name expected
[C++ Error] powrprof.h(48): E2228 Too many error or warning messages
是什么原因导致的?typedef DWORD (WINAPI *TPowerDuplicateScheme)(HKEY, const GUID *, GUID **);
HINSTANCE hDll = ::LoadLibraryW(L"PowrProf.dll");
if (hDll)
{
TPowerDuplicateScheme pds = (TPowerDuplicateScheme)::GetProcAddress(hDll, "PowerDuplicateScheme");
if (pds)
{
// 调用PowerDuplicateScheme的代码写在这里:
// pds(aa, bb, cc);
// ...
}
::FreeLibrary(hDll);
}
#include <vcl.h>
#include <powrprof.h>
#pragma link "C:\\Program Files\\Borland\\CBuilder6\\Lib\\powrprof.lib"
#pragma hdrstop
#include "Unit1.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
}
//---------------------------------------------------------------------------
const GUID FAR GUID_POWER_SAVER ={ 0xa1841308, 0x3541, 0x4fab, { 0xbc, 0x81, 0xf7, 0x15, 0x56, 0xf2, 0x0b, 0x4a } }; // 节能
//a1841308-3541-4fab-bc81-f71556f20b4a
const GUID FAR GUID_BALANCED ={ 0x381b4222, 0xf694, 0x41f0, { 0x96, 0x85, 0xff, 0x5b, 0xb2, 0x60, 0xdf, 0x2e } }; // 平横
//381b4222-f694-41f0-9685-ff5bb260df2e
const GUID FAR GUID_HIGH_PERFORMANCE ={ 0x8c5e7fda, 0xe8bf, 0x4a96, { 0x9a, 0x85, 0xa6, 0xe2, 0x3a, 0x8c, 0x63, 0x5c } }; // 高性能
void __fastcall TForm1::Button1Click(TObject *Sender)
{
WCHAR displayBuffer[_MAX_PATH] = L"超级节能";
DWORD displayBufferSize = _MAX_PATH;
GUID *GUID_HIGH_POWERSAVE = NULL;
if(ERROR_SUCCESS == PowerDuplicateScheme(NULL,&GUID_BALANCED,&GUID_HIGH_POWERSAVE))
{
ShowMessage("DuplicateScheme ok");
}
}
仍然提示:
[C++ Error] Unit1.cpp(34): E2268 Call to undefined function 'PowerDuplicateScheme'