Calling 4GL functions from C

It is possible to call a 4GL function from within the C code. To do that, you need to use the API defined in fglapi.h.

Note: To call 4GL functions from static C libraries directly, you must set the QX_WRAPPER environment variable.

After you set QX_WRAPPER=1, wrappers will be generated automatically when you deploy the application from LyciaStudio.

Otherwise, you can call 4GL functions from dynamic C libraries only indirectly.

The input parameters of the 4GL function you will call can be passed using the push functions — such as pushint. The output parameters can be retrieved using pop functions — such as popint. Most of the push and pop functions are declared in the following file: <LYCIA_DIR>/include/fglsys.h.

 

Calling a function in the currently loaded PCode module:

int fgl_call(const char *funcname, int nargs);

 

Here is an example of calling a 4GL function from a C program. Suppose we want the following 4GL function to be callable from our C program:

# my_4gl_src.4gl

FUNCTION my_4gl_func(n)

 DEFINE n INTEGER

 RETURN n / 2, n * 2

END FUNCTION

 

We can call this function from our C program as follows:

/* my_c_src.c */

#include "fglapi.h"

#include "fglsys.h"

#include <stdio.h>

int main() {

 int n1, n2;

 pushint(10);

 fgl_call(my_4gl_func, 1);

 popint(&n1);

 popint(&n2);

 printf("%d\n", n1);

 printf("%d\n", n2);

 return(0);

}

The 4GL source can be compiled using qxld or qxcc, or LyciaStudio interface, as per usual. When we compile the C source, the resultant executable will need to be linked against lib4glc in the Lycia distribution.

 

 

Contact Us

Privacy Policy

Copyright © 2024 Querix, (UK) Ltd.