Example 1: Calling an IBM PASE for i procedure from within IBM® i programs
This example shows an ILE program calling an PASE for i procedure.
Note: By using the code examples, you agree to the terms
of the Code license and disclaimer information.
#include <stdio.h>
#include <qp2shell2.h>
#include <qp2user.h>
#define JOB_CCSID 0
int main(int argc, char *argv[])
{
QP2_ptr64_t id;
void *getpid_pase;
const QP2_arg_type_t signature[] = { QP2_ARG_END };
QP2_word_t result;
/*
* Call QP2SHELL2 to run the PASE for i program
* /usr/lib/start32, which starts PASE for i in
* 32-bit mode (and leaves it active on return)
*/
QP2SHELL2("/usr/lib/start32");
/*
* Qp2dlopen opens the global name space (rather than
* loading a new shared executable) when the first
* argument is a null pointer. Qp2dlsym locates the
* function descriptor for the PASE for i getpid
* subroutine (exported by shared library libc.a)
*/
id = Qp2dlopen(NULL, QP2_RTLD_NOW, JOB_CCSID);
getpid_pase = Qp2dlsym(id, "getpid", JOB_CCSID, NULL);
/*
* Call Qp2CallPase to run the PASE for i getpid
* function, and print the result. Use Qp2errnop
* to find and print the PASE for i errno if the
* function result was -1
*/
int rc = Qp2CallPase(getpid_pase,
NULL, // no argument list
signature,
QP2_RESULT_WORD,
&result)
printf("PASE for i getpid() = %i\n", result);
if (result == -1)
printf("IBM i errno = %i\n", *Qp2errnop());
/*
* Close the Qp2dlopen instance, and then call
* Qp2EndPase to end PASE for i in this job
*/
Qp2dlclose(id);
Qp2EndPase();
return 0;
}