Syntax
#include <stdio.h> int _set_crt_msg_handle(int fh);Description
Use _set_crt_msg_handle to trap run-time message output in applications where handle 2 is not defined, such as Presentation Manager applications.
The file handle fh must be a writable file or pipe handle. Set fh only for the current library environment.
This example causes an exception by dereferencing a null pointer and uses _set_crt_msg_handle to send the exception messages to the file _scmhdl.out.
#include <sys\stat.h> #include <io.h> #include <fcntl.h> #include <stdio.h> #include <stdlib.h> int main(void) { int fh; char *p = NULL; if (-1 == (fh = open("_scmhdl.out", O_CREAT|O_TRUNC|O_RDWR, S_IREAD|S_IWRITE))) { perror("Unable to open the file _scmhdl.out."); exit(EXIT_FAILURE); } /* change file handle where messages are sent */ if (fh != _set_crt_msg_handle(fh)) { perror("Could not change massage output handle."); exit(EXIT_FAILURE); } *p = 'x'; /* cause an exception, output should be in _scmhdl.out */ if (-1 == close(fh)) { perror("Unable to close _scmhdl.out."); exit(EXIT_FAILURE); } return 0; /**************************************************************************** Running this program would cause an exception to occur, the file _scmhdl.out should contain the exception messages similar to : Exception = c0000005 occurred at EIP = 10068. ****************************************************************************/ }Related Information