Win32 GUI app: how to get stderr messages into messagebox
I'm attempting to use procedures from a library written in the C language in an Win32 gui application.
The author of this library logs error 开发者_StackOverflow社区messages to stderr as below.
fprintf(stderr, "Error in %s: %s\n", procname, msg);
How can I get the messages printed to stderr into a messagebox?
Thanks.
You can use SetStdHandle to select another handle as your process' stderr
. Create a pipe, have a thread waiting for information on that pipe and set that pipe's write handle as stderr
. If you define a large enough buffer, you can probably skip the thread and just read the data from the pipe after each call to the library.
If you have access to the code then the easiest way is to just sprintf to a buffer and call MessageBox() - rather than doing some level redirect of stderr.
精彩评论