Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Windows API problem

Status
Not open for further replies.

CitizenBleys

Programmer
Jul 12, 2003
23
CA
I created a simple Log Off application using Visual C++ 6.0; It was painfully easy, all I had to do was create a new Win32 application, gave it the "Simple Win32 Application" template, and replaced the TODO comment with ExitWindowsEx(EWX_LOGOFF | EWX_FORCE,0);, and it worked absolutely perfectly.

Now, I wanted to create a version that would lock the workstation. I looked up ExitWindowsEx in the help and clicked on System Shutdown Functions under See Also, and found a function called LockWorkStation, which, according to the Help file, was exactly what I was looking for; It was defined in the same header as ExitWindowsEx, was also stored in user32.lib...basically, it's exactly identical except that it locks the workstation instead of logging out.

Problem is, it doesn't work. At all. When I type it in, the parameter list (in this case, VOID) comes up, when I hover over it, I see the prototype, and when I hit F1, I get the help file. But when I compile, it says "error C2065: 'LockWorkStation' : undeclared identifier"

It's *not* an undelared identifier, it's part of the API.

What the *expletives deleted* do I have to do to accomplish what ought to be a dead simple API call? I even tried loading Visual Basic, even though I don't know anything about Visual Basic, and managed to accomplish...precisely bugger. VB won't make the API call, either.
 
You must have the same function name in your class or header file (if not using a class). Preceed the call with :: and you will get it.

::LockWorkStation(params)

Matt
 
Under here you find the requirements (taken from MSDN Library) for LockWorkStation.

Requirements
Windows NT/2000/XP: Included in Windows 2000 and later.
Windows 95/98/Me: Unsupported.
Header: Declared in Winuser.h; include Windows.h.
Library: Use User32.lib.

The real problem is, it was introduced in W2000, meaning 1999. VC6 is released in 1998, so it doen't know of LockWorkStation yet.

You have 2 possibilities:
1. Upgrade your header files
2. Call it dynamic:
- call GetModuleHandle or LoadLibrary on user32.dll
- with the handle from the previous step, call GetProcAddress to get the address of LockWorkStation
- call it



Marcel
 
From winuser.h:

Code:
#if(_WIN32_WINNT >= 0x0500)
WINUSERAPI
BOOL
WINAPI
LockWorkStation(
    VOID);
#endif /* _WIN32_WINNT >= 0x0500 */

So you have to make sure that you've defined _WIN32_WINNT >= 0x0500. Thats the only problem. You'll have to make the target OS Win2k or higher. This is done to prevent compatibility problems with older versions of windows.
 
just change
#include<windows.h>
to
#define _WIN32_WINNT 0x0500
#include<windows.h>


Ion Filipski
1c.bmp

ICQ: 95034075
AIM: IonFilipski
filipski@excite.com
 
I did the solution mentioned by updating the headerfile.
But when i execute,I get a message &quot;Procedure entrypoint LockWorkStation could not be located in user32.dll&quot;
I checked User32.dll and it has a function named &quot;LockWindowStation&quot;.I tried using this without any sucess
 
That's probably because you are trying to use the program on a Windows 95/98/Me/NT machine.

It's ONLY supported on Windows 2000 and above as it clearly says on the MSDN. As far as I know there doesn't exist a function named LockWindowStation. Aren't you confusing that with LockWindowUpdate?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top