Example: CL Program that Passes Parameters to an ILE C++ Program
The CL program CLPROG1 passes the parameters v, d, h, i, j to
an ILE C++ program MYPROG1.
Note: To pass parameters
to an ILE program when you run it, use the PARM option of the CL Call
(CALL) command.
The parameters are null-terminated within the the CL program CLPROG1.
They are passed by reference. All incoming arguments to MYPROG1 are
pointers. Figure 1. Example of CL Program that
Passes Arguments to an ILE C++ Program.
The CL program CLPROG1 receives its input values
from a CL Command Prompt MYCMD1 which prompts the
user to input the desired values. The source code for MYCMD1 is:
Figure 2. Example of Generic CL Command Prompt.
After the CL program CLPROG1 has received
the user input from the command prompt MYCMD1, it
passes the input values on to a C++ program MYPROG1.
The source code for this program is contained in myprog1.cpp:
Figure 3. Example of C++ Program that Receives
Arguments (Pointers) by Reference.
// myprog1.cpp
#include <iostream.h>
#include <stdlib.h>
#include <string.h>
#include <bcd.h>
// Arguments are received by reference from CL program CLPROG1
// Incoming arguments are all pointers
int main(int argc, char *argv[])
{
char *v;
char *h;
char *i;
char *j;
_DecimalT <10, 1> d;
v = argv[1];
d = *((_DecimalT <10,1> *) argv[2]);
h = argv[3];
i = argv[4];
j = argv[5];
cout << " v= " << v
<< " d= " << d
<< " h= " << h
<< " i= " << i
<< " j= " << j
<< endl;
}
If the CL program CLPROG1 passes the following
parameters to the C++ program MYPROG1:
'123.4', 123.4, 'Hi', LO, and '1'
the
output from program MYPROG1 is:
v= 123.4 HI LO 1 d= 123.4 h= HI LO 1
i= LO 1 j= 1
Press ENTER to end terminal session.