BNSYM tool v0.8.108 (beta)

(C) 2002 by Thomas Bleeker. Last update July 7th, 2002.

BNSYM is a tool to automatically create a COFF object file with symbols the program can use to tell the current build number. The tool reads a small text configuration file, increments the build number and writes a COFF object file (.obj) with two (or one, depending on the configuration).

The two symbols that are written to the object file are current_build_value and current_build_string. current_build_value is just a dword value that contains the current build number. current_build_string is a null terminated string, of which the format depends on the configuration file.

Using the tool

Syntax:

  bnsym [-c configfile] [-o outputfile] [-s] [-h|-?]

-c configfileSpecifies which configuration file to use.When ommited, defaults to bnconfig.dat
-o outputfileSpecifies which output file to use.When ommited, defaults to bn_data.obj
-sSilent mode, will only display errors.
-h / -?Help mode, will display this message

The program's exit code is 0 if no errors occurred, 1 otherwise.

Using the symbols

All languages: make sure the linker links the object file created by bnsym.

C++

To define the external symbols:

   extern "C" char current_build_string[];
   extern "C" long current_build_value;

Example of using the symbols:

   char buffer[128];
   wsprintf(buffer, "The build number is %d.", current_build_value);
   MessageBox(NULL, current_build_string, buffer, MB_OK);

C

   extern char current_build_string[];
   extern long current_build_value;

Example of using the symbols:

   char buffer[128];
   wsprintf(buffer, "The build number is %d.", current_build_value);
   MessageBox(NULL, current_build_string, buffer, MB_OK);

MASM

   extern current_build_value:DWORD
   extern current_build_string:BYTE

Example of using the symbols:

.data
   format db "The build number is %d.", 0
.data?
   buffer db 128 dup (?)
.code

start:
   invoke   wsprintf, addr buffer, addr format, current_build_value
   invoke   MessageBox, 0, addr current_build_string, addr buffer, 0

The configuration file

The configuration file looks like this:

current_build=8
build_value=1
build_string=Build #%n on %d %t.

(note: the lines have to start with 'setting=' in that form, no spaces. After the = sign, spaces are allowed. Also, all lines without settings are ignored and removed when the file is updated).

current_build is the current build number. This value is automatically incremented each time the tool is run. If it's ommitted, a warning is shown and the value is set to 1.

build_value can be 0 or 1 (or any number actually). If it's 0, the current_build_value symbol is not included in the object file. If it's not 0, the symbol is included. If the setting is omitted, it defaults to 0. When the setting is 0, it will be removed when the config file is updated.

build_string is the format for the current_build_string symbol. If it's omitted, the symbol is not included in the object file. Otherwise, the string is used to format the symbol string. Three special characters can be used: %n for the current build number, %d for the current date (yyyy-mm-dd), %t for the current time (hh:mm:ss).

Running the tool automatically each build

MASM

For MASM, you probably have a .bat or a makefile you use to assemble your project. Just add the right command line for bnsym just before the linker is run. Also, make sure your .bat/makefile can find bnsym.

Visual C++ project

(Note, Visual C++ 6 is used in the examples below)

First of all, copy bnsym.exe to a directory in Visual C's bin directory (usually something like program files\Microsoft Visual Studio\VC98\bin).

To run the tool automatically each time your Visual C++ project is built, define a pre-linker step and add the output object file to the object list.


Add the correct command line for bnsym as a pre-link command.


Add the output object file to the link list.