LockWorkStation()

This is a discussion on LockWorkStation() within the Windows Programming forums, part of the Platform Specific Boards category; I'm having trouble calling LockWorkStation() which is declared in winuser.h and requires user32.lib(standard lib) and Microsoft's documentation says to just ...

  1. #1
    Master of the Universe! velius's Avatar
    Join Date
    Sep 2003
    Posts
    219

    LockWorkStation()

    I'm having trouble calling LockWorkStation() which is declared in winuser.h and requires user32.lib(standard lib) and Microsoft's documentation says to just include windows.h Both VC++ 6.0 and 7.0 (.Net) complain the function is not declared. How do you use this function? What am I missing?
    While you're breakin' down my back n'
    I been rackin' out my brain
    It don't matter how we make it
    'Cause it always ends the same
    You can push it for more mileage
    But your flaps r' wearin' thin
    And I could sleep on it 'til mornin'
    But this nightmare never ends
    Don't forget to call my lawyers
    With ridiculous demands
    An you can take the pity so far
    But it's more than I can stand
    'Cause this couchtrip's gettin' older
    Tell me how long has it been
    'Cause 5 years is forever
    An you haven't grown up yet
    -- You Could Be Mine - Guns N' Roses

  2. #2
    & the hat of GPL slaying Thantos's Avatar
    Join Date
    Sep 2001
    Posts
    5,681
    LockWorkStation

    The LockWorkStation function submits a request to lock the workstation's display. Locking a workstation protects it from unauthorized use.

    BOOL LockWorkStation(void);
    Parameters
    This function has no parameters.
    Return Values

    If the function succeeds, the return value is nonzero. Because the function executes asynchronously, a nonzero return value indicates that the operation has been initiated. It does not indicate whether the workstation has been successfully locked.

    If the function fails, the return value is zero. To get extended error information, call GetLastError.
    Remarks

    Common reasons the workstation might not be locked even if the function succeeds include the following: no user is logged on, the workstation is already locked, the process is not running on the interactive desktop, or the request is denied by the Graphical Identification and Authentication (GINA) DLL.

    This function has the same result as pressing Ctrl+Alt+Del and clicking Lock Workstation. To unlock the workstation, the user must log in.
    http://msdn.microsoft.com/library/de...orkstation.asp

    It seems pretty stright forword to me. Call the function and do any error checking needed.

  3. #3
    erstwhile
    Join Date
    Jan 2002
    Posts
    2,227

    Re: LockWorkStation()

    Originally posted by velius
    I'm having trouble calling LockWorkStation() which is declared in winuser.h and requires user32.lib(standard lib) and Microsoft's documentation says to just include windows.h Both VC++ 6.0 and 7.0 (.Net) complain the function is not declared. How do you use this function? What am I missing?
    If you open up winuser.h and look for the function you'll see right away what's missing. The function is defined within a preprocessor conditional so you'll need to meet that requirement otherwise you'll continue to get the 'function not declared' error.

    In short, #define _WIN32_WINNT 0x0500 prior to #including windows.

    This is a fairly common problem; for more information, check out this page on msdn which should give you a more precise value for the above macro depending on your target operating system.
    Last edited by Ken Fitlike; 09-07-2003 at 09:57 AM.
    CProgramming FAQ
    Caution: this person may be a carrier of the misinformation virus.

  4. #4
    Master of the Universe! velius's Avatar
    Join Date
    Sep 2003
    Posts
    219
    Thantos I already read the MSDN pages. Geez do you think I'm some lame noobie? Besides I said the compiler claimed the function was not declaired!

    Thank you Ken that did the trick!
    While you're breakin' down my back n'
    I been rackin' out my brain
    It don't matter how we make it
    'Cause it always ends the same
    You can push it for more mileage
    But your flaps r' wearin' thin
    And I could sleep on it 'til mornin'
    But this nightmare never ends
    Don't forget to call my lawyers
    With ridiculous demands
    An you can take the pity so far
    But it's more than I can stand
    'Cause this couchtrip's gettin' older
    Tell me how long has it been
    'Cause 5 years is forever
    An you haven't grown up yet
    -- You Could Be Mine - Guns N' Roses

  5. #5
    & the hat of GPL slaying Thantos's Avatar
    Join Date
    Sep 2001
    Posts
    5,681
    Geez do you think I'm some lame noobie?
    Looking at your avatar, yes

  6. #6
    Master of the Universe! velius's Avatar
    Join Date
    Sep 2003
    Posts
    219
    Don't judge a book by its cover. If you don't like SpongeBob SquarePants that's fine. Just so you know from now on I've been programming with C++ for over 5 years and C for around 3. I've also been using MFC for more than 2 years and Win32 API for over 1 year. I also like using Qt for Linux. You just have no class!
    Last edited by velius; 09-07-2003 at 03:44 PM.
    While you're breakin' down my back n'
    I been rackin' out my brain
    It don't matter how we make it
    'Cause it always ends the same
    You can push it for more mileage
    But your flaps r' wearin' thin
    And I could sleep on it 'til mornin'
    But this nightmare never ends
    Don't forget to call my lawyers
    With ridiculous demands
    An you can take the pity so far
    But it's more than I can stand
    'Cause this couchtrip's gettin' older
    Tell me how long has it been
    'Cause 5 years is forever
    An you haven't grown up yet
    -- You Could Be Mine - Guns N' Roses

  7. #7
    I am the worst best coder Quantrizi's Avatar
    Join Date
    Mar 2002
    Posts
    644
    Originally posted by velius
    Don't judge a book by its cover. If you don't like SpongeBob SquarePants that's fine. Just so you know from now on I've been programming with C++ for over 5 years and C for around 3. I've also been using MFC for more than 2 years and Win32 API for over 1 year. I also like using Qt for Linux. You just have no class!
    I am pretty sure that Thantos was being smart.......chill dude.

  8. #8
    Carnivore ('-'v) Hunter2's Avatar
    Join Date
    May 2002
    Posts
    2,879
    >>Geez do you think I'm some lame noobie?
    Looking at your avatar, yes
    Heh... I had the exact same reaction as Thantos when I read that
    Just Google It. √

    (\ /)
    ( . .)
    c(")(") This is bunny. Copy and paste bunny into your signature to help him gain world domination.

  9. #9
    & the hat of GPL slaying Thantos's Avatar
    Join Date
    Sep 2001
    Posts
    5,681
    Me? Being a smart ass? NEVER

Popular pages Recent additions subscribe to a feed

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21