views:

87

answers:

3

Hi All,

I am writing an application in which I got to lock the computer screen (OS is Windows). My Application is in C++. For this purpose I used the LockWorkStation() API defined on msdn, http://msdn.microsoft.com/en-us/library/aa376875%28VS.85%29.aspx

I have included windows.h as told but still I am getting compilation error:

.\source.cpp(5) : error C3861: 'LockWorkStation': identifier not found

here is a sample code thats giving error.

#include <Windows.h>
int main()
{
    LockWorkStation();
    return 0;
}

Please tell me what I am missing here :(

I am using MS-Visual studio 2005.

Regards.

+2  A: 

That function was not supported until Windows 2000. The header files are versioned to allow you to build for older versions of Windows. You're going to want to tell the compiler which minimum version of Windows you want to support as follows:

#define _WIN32_WINNT 0x0500
#define WINVER 0x0500
...
#include <windows.h>

If you open winuser.h, you can see that it is surrounded by #if(_WIN32_WINNT >= 0x0500) ... #endif, meaning that it is not available unless you are targeting Windows 2000 or higher.

See http://msdn.microsoft.com/en-us/library/aa383745(VS.85).aspx for more information on the version macros. There's also the new NTDDI_VERSION define where you can set them all at once.

Tadmas
Thank you so much. That solved the problem :)
Microkernel
Since those defines will change the size of structures, its not so much a minimum version, more like "this version only" if you are not careful. The other option is to delayload (or use GetProcAddress)
Anders
A: 

Will the solution given out apply if the visual studio in use is Visual Studio .Net 2003.

Thanks. Thakur

Thakur
I guess it works... I tried it with VS-2005.
Microkernel
A: 

This is a std MFC dialog based application.I have the following header files declared,

include

include

ifdef _DEBUG

define new DEBUG_NEW

endif

define _WIN32_WINNT 0x0500

define WINVER 0x0500

In one of the event handlers, I use "LockWorkStation()" API to which i get the following error, error C3861: 'LockWorkStation': identifier not found, even with argument-dependent lookup

Let me know if I am missing out on anything during compilation.

Thanks.

Thakur