Help with writing an Application for XPe.

A

AS

Hi All,

I'm trying to write an Appln. for XPe that would enable me to put the system
into suspend mode...
I'm using Visual Studio .NET 2003 with the latest service packs and
everything on my Win2K development system.. As per documentation, one
should include the Powrprof.h and the Powrprof.lib in the application and
call the system functions for power mgmt. as given in
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/power/base/ispwrsuspendallowed.asp
... Here's a sample of my appln.

/********************************/
#include "stdafx.h"
#include "windows.h"
#include "powrprof.h" /** powrprof.lib included in link options */

#define TRUE 1

int _tmain(int argc, _TCHAR* argv[])
{

printf("Checking for the system sleep\n");

if ( IsPwrSuspendAllowed () == TRUE)
{
printf("Suspend state is allowed\n");
}
else
{
printf("Suspend state is NOT allowed\n");
return 0;
}
return 0;

}
/***************************/

Now this compiles fine, but I always get the following error during
linking..
error LNK2019: unresolved external symbol "unsigned char __stdcall
IsPwrSuspendAllowed(void)" (?IsPwrSuspendAllowed@@YGEXZ) referenced in
function _main


Am I missing something here... I'd appreciate any help on this...
Thanks,
Regards,
 
S

Slobodan Brcin

Wrong news group for this kind of question ;)

Have you tried?

#extern "C"
{
#include "powrprof.h" /** powrprof.lib included in link options */
}

Regards,
Slobodan
 
E

Eberhard Schefold

AS said:
error LNK2019: unresolved external symbol "unsigned char __stdcall
IsPwrSuspendAllowed(void)" (?IsPwrSuspendAllowed@@YGEXZ) referenced in
function _main

Am I missing something here... I'd appreciate any help on this...

You forgot to link the respective import library, in this case powrprof.lib
(see MSDN entry to IsPwrSuspendAllowed).

By any means, a VC group would be more appropriate for this question.
 
A

AS

The powrprof.lib is already linked in through the Config Properties->Linker
option->Input->Additional dependencies. Is that Ok, or do I have to do
something additional..??

Thanks,
Regards
AS
 
S

Slobodan Brcin

I don't know if you have seen my previous answer, but you MUST either write
C program or use:

extern "C"
{
#include "powrprof.h" /** powrprof.lib included in link options */
}

Isn't this obvious?


Regards,
Slobodan
 
E

Eberhard Schefold

AS said:
The powrprof.lib is already linked in through the Config
Properties->Linker option->Input->Additional dependencies. Is that
Ok, or do I have to do something additional..??

Sorry, you already did write that. I'll try to pay better attention next
time.

Slobodan had the right hint, as usual. There seem to be some problems
with the Power Schemes header files, as mentioned in MSDN under

Windows Development
Windows Base Services
Power Management
SDK Documentation
About Power Management
Power Schemes

Note that the initial versions of Powrprof.h included some potential
problems. This file cannot be included multiple times, or be included in
a .cpp file, unless its contents are bracketed as follows:

#ifndef _HEADERFILENAME_H_
#define _HEADERFILENAME_H_

#ifdef __cplusplus
extern "C" {
#endif

<Contents of header file>

#ifdef __cplusplus
}
#endif

#endif // _HEADERFILENAME_H_
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top