Click to See Complete Forum and Search --> : SetSuspendState


honae
March 20th, 2006, 09:34 AM
I'm trying make a program to hibernate the Windows. Then I'm using the setSuspendState function. But, when I compile the source code I get the following errors:

--------------------Configuration: hibernate - Win32 Debug--------------------
Compiling...
hibernate.cpp
c:\microsoft sdk\include\powrprof.h(18) : error C2146: syntax error : missing ';' before identifier 'LidOpenWakeAc'
c:\microsoft sdk\include\powrprof.h(18) : error C2501: 'SYSTEM_POWER_STATE' : missing storage-class or type specifiers
c:\microsoft sdk\include\powrprof.h(18) : error C2501: 'LidOpenWakeAc' : missing storage-class or type specifiers
c:\microsoft sdk\include\powrprof.h(19) : error C2146: syntax error : missing ';' before identifier 'LidOpenWakeDc'
c:\microsoft sdk\include\powrprof.h(19) : error C2501: 'SYSTEM_POWER_STATE' : missing storage-class or type specifiers
c:\microsoft sdk\include\powrprof.h(19) : error C2501: 'LidOpenWakeDc' : missing storage-class or type specifiers
c:\microsoft sdk\include\powrprof.h(25) : error C2146: syntax error : missing ';' before identifier 'PowerButtonAc'
c:\microsoft sdk\include\powrprof.h(25) : error C2501: 'POWER_ACTION_POLICY' : missing storage-class or type specifiers
c:\microsoft sdk\include\powrprof.h(25) : error C2501: 'PowerButtonAc' : missing storage-class or type specifiers
c:\microsoft sdk\include\powrprof.h(26) : error C2146: syntax error : missing ';' before identifier 'PowerButtonDc'
c:\microsoft sdk\include\powrprof.h(26) : error C2501: 'POWER_ACTION_POLICY' : missing storage-class or type specifiers
c:\microsoft sdk\include\powrprof.h(26) : error C2501: 'PowerButtonDc' : missing storage-class or type specifiers
c:\microsoft sdk\include\powrprof.h(27) : error C2146: syntax error : missing ';' before identifier 'SleepButtonAc'
c:\microsoft sdk\include\powrprof.h(27) : error C2501: 'POWER_ACTION_POLICY' : missing storage-class or type specifiers
c:\microsoft sdk\include\powrprof.h(27) : error C2501: 'SleepButtonAc' : missing storage-class or type specifiers
c:\microsoft sdk\include\powrprof.h(28) : error C2146: syntax error : missing ';' before identifier 'SleepButtonDc'
c:\microsoft sdk\include\powrprof.h(28) : error C2501: 'POWER_ACTION_POLICY' : missing storage-class or type specifiers
c:\microsoft sdk\include\powrprof.h(28) : error C2501: 'SleepButtonDc' : missing storage-class or type specifiers
c:\microsoft sdk\include\powrprof.h(29) : error C2146: syntax error : missing ';' before identifier 'LidCloseAc'
c:\microsoft sdk\include\powrprof.h(29) : error C2501: 'POWER_ACTION_POLICY' : missing storage-class or type specifiers
c:\microsoft sdk\include\powrprof.h(29) : error C2501: 'LidCloseAc' : missing storage-class or type specifiers
c:\microsoft sdk\include\powrprof.h(30) : error C2146: syntax error : missing ';' before identifier 'LidCloseDc'
c:\microsoft sdk\include\powrprof.h(30) : error C2501: 'POWER_ACTION_POLICY' : missing storage-class or type specifiers
c:\microsoft sdk\include\powrprof.h(30) : error C2501: 'LidCloseDc' : missing storage-class or type specifiers
c:\microsoft sdk\include\powrprof.h(31) : error C2146: syntax error : missing ';' before identifier 'DischargePolicy'
c:\microsoft sdk\include\powrprof.h(31) : error C2501: 'SYSTEM_POWER_LEVEL' : missing storage-class or type specifiers
c:\microsoft sdk\include\powrprof.h(31) : error C2065: 'NUM_DISCHARGE_POLICIES' : undeclared identifier
c:\microsoft sdk\include\powrprof.h(31) : error C2057: expected constant expression
c:\microsoft sdk\include\powrprof.h(31) : error C2501: 'DischargePolicy' : missing storage-class or type specifiers
c:\microsoft sdk\include\powrprof.h(53) : error C2146: syntax error : missing ';' before identifier 'MinSleepAc'
c:\microsoft sdk\include\powrprof.h(53) : error C2501: 'SYSTEM_POWER_STATE' : missing storage-class or type specifiers
c:\microsoft sdk\include\powrprof.h(53) : error C2501: 'MinSleepAc' : missing storage-class or type specifiers
c:\microsoft sdk\include\powrprof.h(54) : error C2146: syntax error : missing ';' before identifier 'MinSleepDc'
c:\microsoft sdk\include\powrprof.h(54) : error C2501: 'SYSTEM_POWER_STATE' : missing storage-class or type specifiers
c:\microsoft sdk\include\powrprof.h(54) : error C2501: 'MinSleepDc' : missing storage-class or type specifiers
c:\microsoft sdk\include\powrprof.h(55) : error C2146: syntax error : missing ';' before identifier 'ReducedLatencySleepAc'
c:\microsoft sdk\include\powrprof.h(55) : error C2501: 'SYSTEM_POWER_STATE' : missing storage-class or type specifiers
c:\microsoft sdk\include\powrprof.h(55) : error C2501: 'ReducedLatencySleepAc' : missing storage-class or type specifiers
c:\microsoft sdk\include\powrprof.h(56) : error C2146: syntax error : missing ';' before identifier 'ReducedLatencySleepDc'
c:\microsoft sdk\include\powrprof.h(56) : error C2501: 'SYSTEM_POWER_STATE' : missing storage-class or type specifiers
c:\microsoft sdk\include\powrprof.h(56) : error C2501: 'ReducedLatencySleepDc' : missing storage-class or type specifiers
c:\microsoft sdk\include\powrprof.h(68) : error C2146: syntax error : missing ';' before identifier 'OverThrottledAc'
c:\microsoft sdk\include\powrprof.h(68) : error C2501: 'POWER_ACTION_POLICY' : missing storage-class or type specifiers
c:\microsoft sdk\include\powrprof.h(68) : error C2501: 'OverThrottledAc' : missing storage-class or type specifiers
c:\microsoft sdk\include\powrprof.h(69) : error C2146: syntax error : missing ';' before identifier 'OverThrottledDc'
c:\microsoft sdk\include\powrprof.h(69) : error C2501: 'POWER_ACTION_POLICY' : missing storage-class or type specifiers
c:\microsoft sdk\include\powrprof.h(69) : error C2501: 'OverThrottledDc' : missing storage-class or type specifiers
c:\microsoft sdk\include\powrprof.h(76) : error C2146: syntax error : missing ';' before identifier 'ProcessorPolicyAc'
c:\microsoft sdk\include\powrprof.h(76) : error C2501: 'PROCESSOR_POWER_POLICY' : missing storage-class or type specifiers
c:\microsoft sdk\include\powrprof.h(76) : error C2501: 'ProcessorPolicyAc' : missing storage-class or type specifiers
c:\microsoft sdk\include\powrprof.h(77) : error C2146: syntax error : missing ';' before identifier 'ProcessorPolicyDc'
c:\microsoft sdk\include\powrprof.h(77) : error C2501: 'PROCESSOR_POWER_POLICY' : missing storage-class or type specifiers
c:\microsoft sdk\include\powrprof.h(77) : error C2501: 'ProcessorPolicyDc' : missing storage-class or type specifiers
c:\microsoft sdk\include\powrprof.h(86) : error C2146: syntax error : missing ';' before identifier 'IdleAc'
c:\microsoft sdk\include\powrprof.h(86) : error C2501: 'POWER_ACTION_POLICY' : missing storage-class or type specifiers
c:\microsoft sdk\include\powrprof.h(86) : error C2501: 'IdleAc' : missing storage-class or type specifiers
c:\microsoft sdk\include\powrprof.h(87) : error C2146: syntax error : missing ';' before identifier 'IdleDc'
c:\microsoft sdk\include\powrprof.h(87) : error C2501: 'POWER_ACTION_POLICY' : missing storage-class or type specifiers
c:\microsoft sdk\include\powrprof.h(87) : error C2501: 'IdleDc' : missing storage-class or type specifiers
c:\microsoft sdk\include\powrprof.h(98) : error C2146: syntax error : missing ';' before identifier 'MaxSleepAc'
c:\microsoft sdk\include\powrprof.h(98) : error C2501: 'SYSTEM_POWER_STATE' : missing storage-class or type specifiers
c:\microsoft sdk\include\powrprof.h(98) : error C2501: 'MaxSleepAc' : missing storage-class or type specifiers
c:\microsoft sdk\include\powrprof.h(99) : error C2146: syntax error : missing ';' before identifier 'MaxSleepDc'
c:\microsoft sdk\include\powrprof.h(99) : error C2501: 'SYSTEM_POWER_STATE' : missing storage-class or type specifiers
c:\microsoft sdk\include\powrprof.h(99) : error C2501: 'MaxSleepDc' : missing storage-class or type specifiers
c:\microsoft sdk\include\powrprof.h(145) : error C2065: 'POWER_ACTION' : undeclared identifier
c:\microsoft sdk\include\powrprof.h(145) : error C2065: 'SYSTEM_POWER_STATE' : undeclared identifier
c:\microsoft sdk\include\powrprof.h(145) : error C2275: 'ULONG' : illegal use of this type as an expression
c:\arquivos de programas\microsoft visual studio\vc98\include\windef.h(43) : see declaration of 'ULONG'
c:\microsoft sdk\include\powrprof.h(145) : error C2275: 'BOOLEAN' : illegal use of this type as an expression
c:\arquivos de programas\microsoft visual studio\vc98\include\winnt.h(636) : see declaration of 'BOOLEAN'
c:\microsoft sdk\include\powrprof.h(145) : error C2165: 'left-side modifier' : cannot modify pointers to data
c:\microsoft sdk\include\powrprof.h(145) : error C2071: 'PFNNTINITIATEPWRACTION' : illegal storage class
c:\microsoft sdk\include\powrprof.h(158) : error C2065: 'PSYSTEM_POWER_CAPABILITIES' : undeclared identifier
c:\microsoft sdk\include\powrprof.h(158) : warning C4229: anachronism used : modifiers on data are ignored
c:\microsoft sdk\include\powrprof.h(162) : error C2065: 'PADMINISTRATOR_POWER_POLICY' : undeclared identifier
c:\microsoft sdk\include\powrprof.h(162) : warning C4229: anachronism used : modifiers on data are ignored
c:\microsoft sdk\include\powrprof.h(174) : error C2065: 'POWER_INFORMATION_LEVEL' : undeclared identifier
c:\microsoft sdk\include\powrprof.h(174) : error C2275: 'PVOID' : illegal use of this type as an expression
c:\arquivos de programas\microsoft visual studio\vc98\include\winnt.h(106) : see declaration of 'PVOID'
c:\microsoft sdk\include\powrprof.h(174) : error C2275: 'ULONG' : illegal use of this type as an expression
c:\arquivos de programas\microsoft visual studio\vc98\include\windef.h(43) : see declaration of 'ULONG'
c:\microsoft sdk\include\powrprof.h(174) : error C2275: 'PVOID' : illegal use of this type as an expression
c:\arquivos de programas\microsoft visual studio\vc98\include\winnt.h(106) : see declaration of 'PVOID'
c:\microsoft sdk\include\powrprof.h(174) : error C2275: 'ULONG' : illegal use of this type as an expression
c:\arquivos de programas\microsoft visual studio\vc98\include\windef.h(43) : see declaration of 'ULONG'
c:\microsoft sdk\include\powrprof.h(174) : warning C4229: anachronism used : modifiers on data are ignored
c:\microsoft sdk\include\powrprof.h(174) : error C2078: too many initializers
c:\microsoft sdk\include\powrprof.h(174) : error C2275: 'ULONG' : illegal use of this type as an expression
c:\arquivos de programas\microsoft visual studio\vc98\include\windef.h(43) : see declaration of 'ULONG'
Error executing cl.exe.

hibernate.exe - 80 error(s), 3 warning(s)

I included the powrprof.h and then these errors showed up.
What I can do to solve the problem?

golanshahar
March 20th, 2006, 10:22 AM
This function requires the latest sdk to be installed, to either install it or use dynamic loading ;)


typedef BOOL (WINAPI *tSetSuspendState )(BOOL,BOOL,BOOL );

tSetSuspendState pSetSuspendState=0;
HINSTANCE handle = ::LoadLibrary("Powrprof.dll");
if ( handle == 0 )
return;

if (handle)
pSetSuspendState = (tSetSuspendState) ::GetProcAddress(handle,"SetSuspendState");


if ( pSetSuspendState)
{
// call function
//pSetSuspendState(,,);
}
::FreeLibrary(handle);


Cheers

wildfrog
March 20th, 2006, 10:47 AM
Are you mixing older with newer versions of the Platform SDKs here?

c:\microsoft sdk\include\powrprof.h(174) : error C2275: 'ULONG' : illegal use of this type as an expression
c:\arquivos de programas\microsoft visual studio\vc98\include\windef.h(43) : see declaration of 'ULONG'

I'm not sure if that is 'safe' to do.

- petter