Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.

run-time environment

michael_green
Beginner
431 Views
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
0 Kudos
1 Reply
Jugoslav_Dujic
Valued Contributor II
431 Views
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
0 Kudos
Reply