Calling QA Build Programs from C

You can easily call a QA Build program from a C program. Below is an example of a call to a QA Build program from an existing DP4 application written in C, with the changes from the original program shown in bold type.

/* LIBMAKE keywords to create .H include file */
/*
#c
#db MYDB
#mapname CPROG
#end
*/
#include "dp4.h"
#include "cprog.h"
#include "cexits.h"
...
void process()
{
  /* C application code */
  ...
  /* calls to QA Build */
  Qab_init();
  Qaction_program("MYPROG");
}

This example assumes that the application database is the same for the C application and the QA Build program, MYPROG. Also in this case there are no calls to DP4 functions in process() after the call to Qaction_program(), but you can include code after the call to Qaction_program() if you like. In this case you should pay attention to the advice in Resuming After Qaction_program().

For an introduction to writing DP4 applications using C see Installing and Using DP4 C Libraries and tools in the C++ Programmers Reference. The following is a summary of the steps needed to convert such a C program to one that calls a QAB program:

  1. Setup and compile the QA Build program.

    The QA Build program is created in the standard way. No additional definitions are required.

  2. Modify the C code

    In many cases this all you do is add calls to the functions Qab_init() and Qaction_program()and include the header file cexits.h that declares them. These functions are described in the section DP4 C Functions for calling QAB programs.

  3. Building the Program

    To build your program you need to include the appropriate QAB library with the list of libraries your program links with. If you are building a legacy program you can use QABLINK to link your program instead of DP4LINK. If you are using Visual C++ then add ntqab.lib (on regular Windows), or ccqab.lib (on Windows CE) to the list of libraries used. On Unix and Linux link with ccqab.a.

    Example command lines to build your program are shown for Windows and Unix below:

    Windows: cl -DWIN32 -Zp1 -Oxs progname.c -link ntqab.lib ntown.lib -entry:mainCRTStartup

    Unix or Linux: $(CC) -o progname $(CFLAGS) progname.c ccqab.a ccown.a

The QA Build program called can perform any action available with QA Build processing, including overlays and C exits.

Unless you call C exits, no extra definitions are required and you do not need to create any C interfaces with PROGCOMP.

If you call C exits, you must modify the source files produced by PROGCOMP to produce a hybrid of the two techniques. You must not try to call a QA Build program from within a C exit.

Adapting Non DP4 Programs

If your program uses only standard C functions, you can call QA Build by making the following changes to your source code:

  1. Include dp4capi.h and cexits.h
  2. Include the file which is generated by LIBMAKE
  3. Rename your main() to process(). You should note that process() is a void function, and that the program exit code must be set by calling dp4_halt()
  4. Add the calls to Qab_init() and Qaction_program()

Once this is done follow the instructions as given in the previous section.