Re: c++ and 4gl
Posted in 2005
Topics: Stored Procedures & SPL, Connectivity: ESQL/C, 4GL & Embedded SQL, Internationalization & Character Sets
Yes you can.
It is just like calling a C function but you must be carefull with the
mangling of the C++ methods.
Call a C wrapper function in the 4gl.
You can use a C module wrapper because you need to use the pop and ret
functions.
In that module call a C++ function that is declared as extern "C" where
you call all C++ code you need.
There is a trick that is to fix the mangling of the functions that is the
final linkage should be made by the c++ compiler.
Folow the 4gl, .c, .cpp and makefile
fgl_call.4gl:
-----------------
# Experiencia de linkagem de C++ com 4gl
main
define valor_retornado char(20)
let valor_retornado = c_wrapper_function("Valor de parametro");
display "Devolvido ao 4gl: ", valor_retornado
end main
-----------------
c_wrapper.c
-----------------
#include <fglsys.h>
int c_wrapper_function()
{
char parametroFgl[31];
char *retornoParamFgl;
extern char *cpp_function(char *val);
popquote(parametroFgl,30);
retornoParamFgl = cpp_function(parametroFgl);
retquote(retornoParamFgl);
return 1;
}
-----------------
cpp_function.cpp
-----------------
#include <iostream>
using namespace std;
namespace teste {
class xpto
{
private:
int x;
public:
xpto() { x=1; };
int getX() { return x; };
};
};
extern "C" {
char *cpp_function(char *parametroFgl)
{
int x;
// Static so para nao ter muito trabalho
static char retornoParamFgl[61];
cout << "String recebida no C++ vinda de 4gl :" << parametroFgl << "\\n";
cout.flush();
using namespace teste;
xpto xp;
x = xp.getX();
cin >> retornoParamFgl;
return retornoParamFgl;
}
}
-----------------
makefile
-----------------
.SUFFIXES: .cpp .4gl .o .per .frm
.cpp.o:
g++ -c $<
.c.o:
c4gl -c $<
.4gl.o:
c4gl -c $<
cpp_fgl_call: c_wrapper.o cpp_function.o fgl_call.o
export INFORMIXC=g++ ; c4gl c_wrapper.o cpp_function.o fgl_call.o -o $@
clean:
rm *.o
-----------------
Cheers
> Hi,
>
> Can I call a c++ function inside my 4gl source?
>
>
> Thank you in advance,
>
> RS
--
S'rgio Ferreira
MoreData <http://www.moredata.pt/>
Subscreva a nossa mailing list
<mailto:minimalist@listserv.moredata.pt?subject=subscribe%20md-info>
sending to informix-list