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
he开发者_JAVA百科re 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.
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.
精彩评论