Subject UDF + Delphi
Author semprolbat
I wrote a function in delphi:

function udftest(i:integer):pChar;

with a corresponding

declare external function udftest
returns cstring(80) free_it
entry_point 'udftest'
module_name 'my_udf.dll';

select udftest(1) from rdb$database; never(?) returns 1.
I guess this is due to a memory-handling issue. According to
Interbase Developer's guide (p78), InterBase uses the STDCALL calling
convention. Udftest is declared as CDECL, which basically is STDCALL
without memory cleanup; the caller has to take care of it. Correct me
if I'm wrong!

I wrote a console application in Delphi from which the function works
just as expected, returning whatever number I use as a parameter,
given that the external function is declared as STDCALL or CDECL.

Out of curiousity I added a few lines of code to udftest that wrote
the integer value to a file, and found that the number was already
crippled when it reached the procedure.

Why is it that Interbase gives a completely different result than
it's supposed to?