I tried to create a simple user defined function (UDF) for Firebird 2.5 with C++ Builder 2010 but I don't manage to get it to work in Firebird.
Adding a unit with my example UDF including "ibase.h" and "ib_util.h":
extern "C" __declspec(dllexport) int __stdcall MYFUNC ( int i )
{
int result = 2 * i;
return result;
}
Building the DLL FBUDFMBD.dll in path C:\Program Files (x86)\Firebird\Firebird_2_5\UDF
Registering my UDF via IBExpert in a sample db with
DECLARE EXTERNAL FUNCTION F_MYFUNC
INTEGER
RETURNS INTEGER
ENTRY_POINT 'MYFUNC' MODULE_NAME 'FBUDFMBD';
Calling the UDF with
select F_MYFUNC( 3 ) from RDB$DATABASE;
results in error message
Invalid token.
invalid request BLR at offset 36.
function F_MYFUNC is not defined.
module name or entrypoint could not be found.
With the tool GExperts - PE Information I can see my UDF as DLL-Export MYFUNC ordinal $1 and entry point $1538.
What I am doing wrong, Firebird can't register my DLL and its UDF correctly?
Is there anything in my DLL project to change regarding to default compiler options?
Thanks a lot! I got it by your help.
top 2: Corrected C++-Code is:
extern "C" __declspec(dllexport) int MYFUNC ( int * val )
{
int result = 2 * *val;
return result;
}
Pay attention to reference call of the input parameter.
top 4: Register the UDF in a firebird 2.5 db by
DECLARE EXTERNAL FUNCTION F_MYFUNC
INTEGER
RETURNS INTEGER BY VALUE
ENTRY_POINT '_MYFUNC' MODULE_NAME 'FBUDFMBD';
Pay attention to the leading underscore at the function name!
top 5: select F_MYFUNC( 3 ) from RDB$DATABASE; works really fine!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With