LockWorkStation function submits a request to lock the workstation's display. Locking a workstation protects it from unauthorized use.
The following example locks the workstation using the
LockWorkStation function. The function requires version Windows 2000 Professional or later.
This example also illustrates load-time dynamic linking. If the DLL is not available, the application using load-time dynamic linking must simply terminate. The run-time dynamic linking example, however, can respond to the error. This is a good way to prevent forced termination. You can use this technique in the applications which should be runnable at all Windows platforms but with delimited functionality following the currently running version of the system.
#define IsWin2000Plus() ((DWORD)(LOBYTE(LOWORD(GetVersion()))) >= 5)
int (__stdcall * MyLockWorkStation)();
int __stdcall WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
LPSTR lpCmdLine, int nCmdShow)
hinstLib = LoadLibrary("USER32.DLL");
MyLockWorkStation = (int (__stdcall *)())
if (MyLockWorkStation != NULL)
MessageBox(NULL, "This application requires"
" Windows 2000 Professional or higher!",
"Lock Workstation", MB_OK);
This application has the same result as pressing Ctrl+Alt+Del and clicking Lock Workstation.