- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I would like to be able to write a generic routine for handling certain run-time errors, and I would like to use it in both Windows applications and console applications. In the former I would use Messagebox for user information while in the latter I would use TYPE *, etc, so in order to be able to do this the routine needs to know what kind of program it is being called from.
I can set up my own environment variable as the first action in any program to tell me this, but is there a better way? Any other comments would be much appreciated.
With many thanks in advance,
Mike
I can set up my own environment variable as the first action in any program to tell me this, but is there a better way? Any other comments would be much appreciated.
With many thanks in advance,
Mike
Link Copied
1 Reply
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
There's no bulletproof way to know what kind of environment you're in, because the output can be redirected to a file or a pipe, a GUI process can allocate console, a console process can create windows, there are services, etc. etc.
I think, however, that a good bet is to use
GetFileType(GetStdHandle(STD_OUTPUT_HANDLE))
which tells you what kind of stuff is stdout. For Win32 GUI applications, it returns 0 (FILE_TYPE_UNKNOWN); for console applications, it is FILE_TYPE_CHAR; for consoles with redirected output, it will be FILE_TYPE_DISK or FILE_TYPE_PIPE. You probably want to distinguish only case 0 (MessageBox) and the other (WRITE(*))
Jugoslav

Reply
Topic Options
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page