all groups > visual c libraries > december 2003 >
You're in the

visual c libraries

group:

Link error LNK2019: unresolved external symbol


Link error LNK2019: unresolved external symbol AS
12/2/2003 5:52:24 PM
visual c libraries: Hi,

I'm trying to use some power management features with windows 2000
Professional and I have visual studio .net 2003 installed with the latest
service packs and everything... I want to write a simple app to turn the
system into sleep mode/suspend mode. As per documentation of ACPI, you can
use the power options by including the Powrprof.h file and use the
Powrprof.lib file in your project, which I did, but when I build, it
compiles fine but I get this Link error.. :

error LNK2019: unresolved external symbol "unsigned char __stdcall
IsPwrSuspendAllowed(void)" (?IsPwrSuspendAllowed@@YGEXZ) referenced in
function _main
fatal error LNK1120: 1 unresolved externals


The code is as shown below :...
Any Ideas on what I'm missing here... please help...

Thanks,
Regards,
AS.

/******************************************/
#include "stdafx.h"

#include "Windows.h"

#include "Powrprof.h"


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

if (isPwrSuspendAllowed() == TRUE) {

printf("Suspend state is allowed\n");

}

else {

printf("Suspend state is NOT allowed\n");

}

return 0;

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



--
AS


RE: Link error LNK2019: unresolved external symbol dgoon NO[at]SPAM online.microsoft.com
12/15/2003 5:02:59 PM
Hi AS,

Thanks very much for your query.

The problem is that the functions in powrprof.lib is exported as plain 'C'
functions. However, when compiling your application, the compiler defaults
to C++ since it sees a .cpp file extension. This causes the
IsPwrSuspendAllowed() API to be 'decorated' and will not match the exports
from the library.

To get around this, you can declare standard 'C' prototypes for the
powrprof.h include as below:

extern "C" {
#include <powrprof.h>
}

This will remove the decoration and your project should link fine (it does
for me).

Hope this helps,
David Goon
Microsoft

This posting is provided "AS IS" with no warranties, and confers no rights.
Use of included script samples are subject to the terms specified at
http://www.microsoft.com/info/cpyright.htm
AddThis Social Bookmark Button