-
May 17th, 2013, 07:19 AM
#1
[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.
-
May 17th, 2013, 07:36 AM
#2
Re: Simple Handle question
Originally Posted by Gerald Bates
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.
Originally Posted by Gerald Bates
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
-
May 17th, 2013, 08:16 AM
#3
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.
-
May 17th, 2013, 09:58 AM
#4
Re: Simple Handle question
Originally Posted by Gerald Bates
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
-
May 18th, 2013, 01:42 AM
#5
Re: Simple Handle question
I understand. Thanks for the replies.
What the mind can conceive it can achieve.
-
May 31st, 2013, 08:42 PM
#6
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|