× The internal search function is temporarily non-functional. The current search engine is no longer viable and we are researching alternatives.
As a stop gap measure, we are using Google's custom search engine service.
If you know of an easy to use, open source, search engine ... please contact support@midrange.com.


  • Subject: RE: How to write a C program, that is to be called from RPG?
  • From: "Bob Crothers" <bob@xxxxxxxxxxxxxx>
  • Date: Tue, 26 Sep 2000 11:52:55 -0500
  • Importance: Normal

Jevgeni,

There is a table in the C reference that equates RPG data types to C data
types.

You will still use main(int argc, char *argv).

But the differences is in how RPG treats stuff and how C treats stuff.  In
particular, character data.

RPG does NOT deal with null terminated strings.  And most of the C functions
expect null terminated strings.  So you will have to be carefull about
translating those.

In general, you RPG passes a pointer to the data. And it does not receive a
return value (This changes with V4 ILE, but you probably must assume OPM
RPG).

Below is a wrapper function for one of my C functions:

void    rSend(int *ReturnCode,
                   struct ccSocketsData *ccs,
                   int  *OpClass,
                   int  *OpSubClass,
                   const void *lpBuf,
                   int  *nBufLen)
{
BYTE wOpClass = (BYTE)*OpClass;
BYTE wOpSubClass = (BYTE)*OpSubClass;

*ReturnCode = ccsSend(ccs, wOpClass, wOpSubClass, lpBuf, *nBufLen);
}

Prototype of the "C" version of this function:

int     ccsSend(struct ccSocketsData *ccs,
                   BYTE OpClass,
                   BYTE OpSubClass,
                   const void *lpBuf,
                   int  nBufLen)

RPG Code that calls this:

C                   CallB     'rSend'
C                   parm                    rc
C                   parm                    CSS
C                   parm                    IPClass
C                   parm                    IPSubClass
C                   parm                    DSCOMMAND
C                   parm                    szData

Note that the RPG is actually ILE, but it is V3R1 compatible ILE so doesn't
have all of the "fancy" stuff that RPG has these days.

Since I am calling procedures, the C side can use varible names and
prototypes.  Since you will actually be calling programs, then your c will
more like:

void main(int argc, char *argv)
{
char    *myParm1;
int     *myParm2;

if (argc < 3)
        {
        printf("life is pretty mucked up...not enough parms");
        Abort.....
        };

myParm1 = argv[1];              //I think arg[0] will be your program name, but 
I might
be wrong!
MyParm2 = (int *)argv[2];

// Now convert myParm1 to null terminated string.

......   Rest of program

// convert myParm1 back to non-null terminated
return;
}


-----Original Message-----
From: owner-c400-l@midrange.com [mailto:owner-c400-l@midrange.com]On Behalf
Of Jevgeni Astanovski
Sent: Tuesday, September 26, 2000 4:26 AM
To: C400-L@midrange.com
Subject: How to write a C program, that is to be called from RPG?


The system, I work with, contain a set of RPG programs (not ILE, I
think).

When I write my ILE/C program, I call them for example like that :

#pragma map(theirapi, "THEIRPROG")
#pragma linkage(theirapi, OS)

void theirapi  ( char *,         /* ERCOD  */
              char *,         /* ERPRM  */
              char *,         /* empty  */
              char *,         /* DSAIF  */
              char *,         /* DSAIR  */
              char *,         /* BEGIN  */
              decimal(5,0) *, /* NOREQ  */
              decimal(5,0) *  /* NORET  */
                );

int main (int argc, char *argv)
{
char          DSAIF[3000];
char          DSAIR[3000];
char          ERCOD[2];
char          ERPRM[10];
char          BEGIN;
char          DUMMY[14] = "              ";
decimal(5,0)  NOREQ;
decimal(5,0)  NORET;

/* Some initialization */
........

/* ------------------- */

theirapi (ERCOD, ERPRM, DUMMY, DSAIF, DSAIR, &BEGIN, &NOREQ, &NORET);

 return(0) ;
}

But these programs are also called from inside the system from other
RPG modules (sources unavailable). Now what I want to do, is to write
my own C program, that can substitute completely one of original
programs - thus being undestinctable from the viewpoint of calling RPG
program. My question is, how should the program access the parameters?
I normally write

int main (int argc, char *argv)

So are there any formal rules for obtaining arguments in C program,
when they are passed from RPG?

Any help will be apreciated,
TIA,

Eugene Astanovsky.




Jevgeni Astanovski,
IT Hooldusosakonna juhataja
Optiva Pank.
+---
| This is the C/400 Mailing List!
| To submit a new message, send your mail to C400-L@midrange.com.
| To subscribe to this list send email to C400-L-SUB@midrange.com.
| To unsubscribe from this list send email to C400-L-UNSUB@midrange.com.
| Questions should be directed to the list owner/operator:
bob@cstoneindy.com
+---


+---
| This is the C/400 Mailing List!
| To submit a new message, send your mail to C400-L@midrange.com.
| To subscribe to this list send email to C400-L-SUB@midrange.com.
| To unsubscribe from this list send email to C400-L-UNSUB@midrange.com.
| Questions should be directed to the list owner/operator: bob@cstoneindy.com
+---

As an Amazon Associate we earn from qualifying purchases.

This thread ...

Replies:

Follow On AppleNews
Return to Archive home page | Return to MIDRANGE.COM home page

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.