home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 11 Util / 11-Util.zip / PMFLAG.ZIP / PMFLAG.C next >
C/C++ Source or Header  |  1991-01-01  |  3KB  |  97 lines

  1. /*
  2.   Message number on bix = ibm.os2/pm # 2116
  3.   Name:   PMWFLAG.C
  4.   Author: Keith Meade
  5.   Date:   12-17-89
  6.  
  7.   PMWFLAG will flag a value in a program's EXE file which will let the
  8.   OS/2 PM know that the program will run in a window.  Use this on utility
  9.   programs that write to STDOUT to keep the PM from flashing to a full
  10.   screen when the program is run from a windowed command session.
  11.  
  12.   Note that this routine is quick-and-dirty.  Make a backup copy of the
  13.   utility before attempting to flag it.
  14.  
  15.   Usage:  PMWFLAG <exe_name>
  16.  
  17.           exe_name = The name of the EXE file to flag.
  18. */
  19.  
  20.  
  21. /*
  22.       This is the response to the question which the above program solves.
  23.      Both of these can be found on bix. I became aware of them after I asked 
  24.      the question of how to run a full-screen program in a text-window.  
  25.      That was message #1087 in ibm.os2/pm.
  26.  
  27.  
  28.   Response by Doug Hamilton.
  29.       The application type (Full-screen, Text windowable or PM Graphics) is
  30.   marked in a flag word in a new header used with os/2 .exe files.  To
  31.   find the appropriate byte, look at the 4-byte long at offset 0x3C (hex)
  32.   from the start of the file.  It will contain a address of the new header,
  33.   which should be 0x0080.  Add 0x0C to that to find the 2-byte unsigned short
  34.   containing the application type flags.
  35.  
  36.   There are lots of things marked in that short, so you have to mask off 
  37.   the 3 bits, 0x0700, to find the bits you need.  They have these values:
  38.  
  39.      Unmarked application      0x0000
  40.      Full Screen application   0x0100
  41.      Text Windowable           0x0200
  42.      PM Graphics               0x0300
  43.  
  44.   (Incidentally, you can tell you've found the new header because the
  45.   first 2 bytes are an unsigned short = 0x454E = "NE".)
  46.  
  47.   You can patch the flag word using patch.exe, though I suggest you
  48.   make a copy first in case you make a typo and need a second try.
  49.   Also, remember that on Intel processors, the low-byte of a 2-byte
  50.   short comes before the high-byte; the low-word of a 4-byte long
  51.   comes before the high word.
  52.  
  53. */
  54.  
  55.  
  56. #include    <stdio.h>
  57. #include    <os2.h>
  58.  
  59. main(argc,argv)
  60. int     argc;
  61. char    *argv[];
  62. {
  63. FILE            *ExeFile;
  64. unsigned long   FileOffset;
  65. unsigned short  FlagWord;
  66.  
  67.     puts("\nPMWFLAG - Flags an EXE file so that is can be run under the OS/2");
  68.  
  69.     puts("          Presentation Manager in a windowed command session.");
  70.  
  71.     if ( argc <= 1 ) {
  72.         puts("\nError - No file name specified.\n");
  73.         exit(1);
  74.     }
  75.  
  76.     if ( (ExeFile = fopen(argv[1],"rb+")) == NULL ) {
  77.         puts("\nError - Unable to open the input file.\n");
  78.         exit(2);
  79.     }
  80.  
  81.     FileOffset = 0x3cL;
  82.     fseek(ExeFile,FileOffset,SEEK_SET);      /* Move file pointer to header #1 */
  83.     fread((char *)&FileOffset,4,1,ExeFile);  /* Read offset of header #2 */
  84.     FileOffset += 0x0cL;                     /* Offset of flag in header #2  */
  85.     fseek(ExeFile,FileOffset,SEEK_SET);      /* Move file pointer to header #2 */
  86.     fseek(ExeFile,FileOffset,SEEK_SET);      /* Move pointer back to header #2 */
  87.  
  88.     fwrite((char *)&FlagWord,2,1,ExeFile);   /* Write the new flag value */
  89.  
  90.     puts("\nFinished OK.\n");
  91.     exit(0);
  92. }
  93.  
  94.  
  95.  
  96.  
  97.