home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
OS/2 Shareware BBS: 11 Util
/
11-Util.zip
/
PMFLAG.ZIP
/
PMFLAG.C
next >
Wrap
C/C++ Source or Header
|
1991-01-01
|
3KB
|
97 lines
/*
Message number on bix = ibm.os2/pm # 2116
Name: PMWFLAG.C
Author: Keith Meade
Date: 12-17-89
PMWFLAG will flag a value in a program's EXE file which will let the
OS/2 PM know that the program will run in a window. Use this on utility
programs that write to STDOUT to keep the PM from flashing to a full
screen when the program is run from a windowed command session.
Note that this routine is quick-and-dirty. Make a backup copy of the
utility before attempting to flag it.
Usage: PMWFLAG <exe_name>
exe_name = The name of the EXE file to flag.
*/
/*
This is the response to the question which the above program solves.
Both of these can be found on bix. I became aware of them after I asked
the question of how to run a full-screen program in a text-window.
That was message #1087 in ibm.os2/pm.
Response by Doug Hamilton.
The application type (Full-screen, Text windowable or PM Graphics) is
marked in a flag word in a new header used with os/2 .exe files. To
find the appropriate byte, look at the 4-byte long at offset 0x3C (hex)
from the start of the file. It will contain a address of the new header,
which should be 0x0080. Add 0x0C to that to find the 2-byte unsigned short
containing the application type flags.
There are lots of things marked in that short, so you have to mask off
the 3 bits, 0x0700, to find the bits you need. They have these values:
Unmarked application 0x0000
Full Screen application 0x0100
Text Windowable 0x0200
PM Graphics 0x0300
(Incidentally, you can tell you've found the new header because the
first 2 bytes are an unsigned short = 0x454E = "NE".)
You can patch the flag word using patch.exe, though I suggest you
make a copy first in case you make a typo and need a second try.
Also, remember that on Intel processors, the low-byte of a 2-byte
short comes before the high-byte; the low-word of a 4-byte long
comes before the high word.
*/
#include <stdio.h>
#include <os2.h>
main(argc,argv)
int argc;
char *argv[];
{
FILE *ExeFile;
unsigned long FileOffset;
unsigned short FlagWord;
puts("\nPMWFLAG - Flags an EXE file so that is can be run under the OS/2");
puts(" Presentation Manager in a windowed command session.");
if ( argc <= 1 ) {
puts("\nError - No file name specified.\n");
exit(1);
}
if ( (ExeFile = fopen(argv[1],"rb+")) == NULL ) {
puts("\nError - Unable to open the input file.\n");
exit(2);
}
FileOffset = 0x3cL;
fseek(ExeFile,FileOffset,SEEK_SET); /* Move file pointer to header #1 */
fread((char *)&FileOffset,4,1,ExeFile); /* Read offset of header #2 */
FileOffset += 0x0cL; /* Offset of flag in header #2 */
fseek(ExeFile,FileOffset,SEEK_SET); /* Move file pointer to header #2 */
fseek(ExeFile,FileOffset,SEEK_SET); /* Move pointer back to header #2 */
fwrite((char *)&FlagWord,2,1,ExeFile); /* Write the new flag value */
puts("\nFinished OK.\n");
exit(0);
}