Subject Re: [firebird-support] Help needed, gen_uuid() UDF for 2.0
Author Magnus Titho
Sasha wrote:
>> Always use ib_util_malloc() to allocate memory for the UDF
>> result string
>> declared as FREE_IT.
>>
>>
> I don't know how to do that. Luckily it's weekend ahead and I've checked out
> firebird source... I only wish I knew any c++ ;)
>
>
I've written an UDF to decode encoded strings in the database [with our
own algorithm in TCodeFunc], and it looks like this:


function ib_util_malloc(l: integer): pointer; cdecl; external 'ib_util.dll';

function Decode_CodeString(const p: PChar): PChar; stdcall;
var
s: string;
begin
s := TCodeFunc.StrToCodStr(string(p));
Result := ib_util_malloc(Length(s) + 1);
StrPCopy(Result, s);
end;


Declaration in Firebird:

DECLARE EXTERNAL FUNCTION Decode_CodeString
CString(255)
RETURNS CString(255) FREE_IT
ENTRY_POINT 'Decode_CodeString' MODULE_NAME '......'

> Thanx...
>
> Sasha
>

--
Magnus