CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 6 of 6
  1. #1
    Join Date
    Jan 2009
    Location
    England
    Posts
    57

    [RESOLVED] Simple Handle question

    When using GetStdHandle() function I can understand you need to make sure that you have a valid Handle to be able to write (output) and read (input) to the console. What I don't understand, is whether obtaining those handles would ever fail? MSDN tells me that I could get INVALID_HANDLE_VALUE or NULL. I have never received those values? Clearly if either write or read handles did produce an error my program should exit?

    This brings me to the STD_ERROR_HANDLE. Is it really necessary to use this handle or even quit a program if this returned an error? This handle is not as important as the two I mentioned earlier?

    I am new to this and just need a better understanding of these handles.
    What the mind can conceive it can achieve.

  2. #2
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,398

    Re: Simple Handle question

    Quote Originally Posted by Gerald Bates View Post
    When using GetStdHandle() function I can understand you need to make sure that you have a valid Handle to be able to write (output) and read (input) to the console. What I don't understand, is whether obtaining those handles would ever fail? MSDN tells me that I could get INVALID_HANDLE_VALUE or NULL. I have never received those values? Clearly if either write or read handles did produce an error my program should exit?
    If your program is about to use a handle that could not be obtained by GetStdHandle (the return value was INVALID_HANDLE_VALUE or NULL) then yes, the program should exit or, at least not use such a handle. Otherwise it will crash.

    Quote Originally Posted by Gerald Bates View Post
    This brings me to the STD_ERROR_HANDLE. Is it really necessary to use this handle or even quit a program if this returned an error?
    If you are not going to write the the standard error device then you don't need to obtain the handle for it.
    Victor Nijegorodov

  3. #3
    Join Date
    Jan 2009
    Location
    England
    Posts
    57

    Re: Simple Handle question

    If you are not going to write to the standard error device then you don't need to obtain the handle for it.
    What is the standard error device? Is this not just outputting an error message to the screen using (I am guessing) GetLastError()? It's clear to me with respect to the other 2 handles what they are needed for? Or, (and I am guessing again,) an error that occurs is redirected to a printer?

    Forgive me for asking what may be a silly question, but I am having trouble explaining this any better.
    What the mind can conceive it can achieve.

  4. #4
    Join Date
    Nov 2000
    Location
    Voronezh, Russia
    Posts
    6,620

    Re: Simple Handle question

    Quote Originally Posted by Gerald Bates View Post
    What is the standard error device? Is this not just outputting an error message to the screen using (I am guessing) GetLastError()?
    Your situation is not about where the error device is outputting to, but it's exactly about whether your code has an intention to write to it. Whatever the device really is, if you don't need to write to it, you never need its handle.
    Best regards,
    Igor

  5. #5
    Join Date
    Jan 2009
    Location
    England
    Posts
    57

    Re: Simple Handle question

    I understand. Thanks for the replies.
    What the mind can conceive it can achieve.

  6. #6
    Join Date
    May 2013
    Posts
    12

    Re: [RESOLVED] Simple Handle question

    If you want to solved your problem or question you must have an idea to develop. Then you can easily Resolved Simple Handle question because you know anything about that.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured