The Logger

The C application in Listing 8-2 (and on the CD) can be used to replace the real C2.EXE file. To replace it, follow these steps:

  1. Rename Visual Basic’s C2.EXE to C3.EXE.

  2. If you want to rebuild the application, make sure the first real line of code in this file reads as here:
    strcat(&carArgs[0], “.\\C3 “);
  3. Copy the EXE (OUTARGS.EXE) to C2.EXE. Your original C2.EXE is now C3.EXE, so no damage is done.
    copy outargs.exe c2.exe
  4. Use Visual Basic 5 as you normally would.

 After you have carried out these steps the following will happen: When Visual Basic 5 runs (to compile to native code), it will run C2.EXE. C2.EXE, really our OUTARGS program, will log the call made to it to the file C2.OUT. (C2 logs to a file based on its own name, <EXEname>.OUT; because our program is named C2.EXE, the log file will be C2.OUT.) Information logged includes the parameters that have been passed to it. C2.EXE will then shell C3.EXE (the “real” C2), passing to it, by default, all the same parameters that it was passed. The net effect is that you have logged how C2 was invoked.

Listing 8-1 is a typical C2.OUT log.

Listing 8-1 Typical C2.OUT log file

********** Run @ Wed Jan 1 00:00:00 1997

* EXE file...

        C2

* Command Line Arguments...

1       -il
2       C:\WINDOWS\TEMP\VB819310
3       -f
4       Form1
5       -W
6       3
7       -Gy
8       -G5
9       -Gs4096
10      -dos
11      -Zl
12      -FoC:\TEMP\Form1.OBJ
13      -QIfdiv
14      -ML
15      -basic
§
* ‘Real’ program and arguments...

        .\C3 -il C:\WINDOWS\TEMP\VB819310 -f Form1 -W 3 -Gy -G5 
        -Gs4096 -dos 
        -Zl -FoC:\TEMP\Form1.OBJ -QIfdiv -ML -basic

********** Run End

The Visual Basic team seems to have added a space between the -W and the 3, possibly causing C2 to interpret this as two separate switches. Since C2 doesn’t error or complain, I’m assuming that it knows what to do with the space.

By further altering the code, you can change, add, or remove compiler switches. For example, you can add the following code to the argument processing loop to replace, say, -G5 with, say, -GB, the “blend” switch mentioned earlier in our discussion of -G5 on page 325.

if(0 == strcmp(argv[nLoop], “-G5”))
{
    (void)strcat(&carArgs[0]   , “-GB “);

    continue;
}

Note This replacement C2 (OUTARGS.EXE) doesn’t like long filenames that include spaces. Each “gap” would cause the next part of the name to be passed to C3 as a separate command-line argument. To fix this, either alter the C code to quote delimit each path or copy your test Visual Basic sample to, say, C:\TEMP before attempting to use it; that is, remove any long pathname. (Leave the renamed outargs C2.EXE in the same folder as the real, now renamed, C3.EXE.)

To restore the “real” program, simply copy over C2.EXE with C3.EXE:

copy c3.exe c2.exe