|
A couple of weeks ago I received some code snippets in reply to a problem I posted regarding dynamic program calls. Barbara Morris (thank you very much Barbara!) posted the original snippets. I'm yet to get a clean-compile but I wanted to post my interpretation of the code and was wondering if somebody could confirm or correct my thoughts please? Following is Barbara's code with my annotations in italics:
#include <miptrnam.h> include files for prototypes.miptrnam holds the prototype for rslvsp. I tried making sense of the header files but could not. I did this to find where _Program comes from in the rslvsp function .
#include <stdio.h>
/*----------------------*/
/* typedef of a program */
/*----------------------*/
typedef void (somepgm_t)(int i, char *p); define the general form of the program that will eventually be called. I'm not sure what the
correct terminology is, but I think this creates a template which the program eventually called has
has to map into?
#pragma linkage(somepgm_t, OS) defines a connection from somepgm_t to the operating system. OS means OS400?
int main(void) the main function in my program.....
{
somepgm_t * somepgm = NULL; the pointer (*somepgm) is of type somepgm_t and is set to NULL which I presume is
a substitute value or a C keyword for all zeroes? Somepgm will later on be set to the system space address of the program I want to call.
char pgmname[11] = "#JUNKLE"; this is the program name. In my program I can just have a string variable and populate it
char libname[11] = "BMORRIS"; according to my own logic. I presume libname can be set to "*LIBL" ?
/*----------------------------*/
/* Get a system pointer to */
/* the program. */
/*----------------------------*/
somepgm = rslvsp (_Program, pgmname, libname, obtain the system space address of where the program held in the pgmname field is.
_AUTH_OBJ_MGMT); I'm unsure where the _Program value comes from. Somepgm was declared earlier
if (somepgm != NULL) If the address is not null then the function found the program and obtained the address
{
somepgm (5, "abcde"); therefore invoke it. The 'form' of the call is as per the typedef earlier.
In my application I need to invoke a program which requires 3 parameters. Each parameter is in fact declared as an external DS via the #PRAGMA mapinc declaration. Do I therefore amend the typedef to look like ......typedef void(somepgm_t) (char *a, char *b, char *c)? where a,b, and c are the structure names assigned by the compiler?
I'm sorry for making this sound complicated, but I thought it might be useful for others approaching C for the first time and used to RPG constructs, especially in the way that external AS/400 objects are made visible to a program.
I've found a book called C For RPG Programmers but delivery is 4 weeks away.
Thank You.
As an Amazon Associate we earn from qualifying purchases.
This mailing list archive is Copyright 1997-2024 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].
Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.