Subject | Re: [firebird-support] Re: UUID (octets) to something readable |
---|---|
Author | Fabiano Bonin |
Post date | 2008-11-20T13:14:30Z |
Hi Wood,
I tried to write the DLL below in Delphi/Windows. They worked fine, but i
found are some issues:
1) In your function 'bin_to_hex', you declare 'len' as longint, but as long
as only the first 2 bytes of an octet represents its length, maybe it should
be declared as word?
2) In your function 'hex_to_bin' it is missing 'cdecl; export;' in front of
it. Was it a typo or they are not required there?
3) I can use the UDF´s in FB only if i don´t use 'FREE_IT' in the function
declaration. If i use FREE_IT they crash the server (FB 2.1). Am i missing
something?
Regards,
Fabiano.
Here is my code:
library ps_udf;
uses
Classes,
SysUtils;
{$R *.res}
function malloc(Size: Integer): Pointer; cdecl; external 'msvcrt.dll';
function bin_to_hex(Token: PChar): PChar; cdecl; export;
var
Len: Word;
begin
Result := nil;
if Token = nil then
Exit;
Len := PWord(Token)^;
Result := malloc(Len * 2 + 1);
BinToHex(@Token[2], Result, Len);
Result[Len * 2] := #0;
end;
function hex_to_bin(Token: PChar): PChar; cdecl; export;
var
Len: LongWord;
begin
Result := nil;
if Token = nil then
Exit;
Len := StrLen(Token);
if Len mod 2 <> 0 then
Exit;
Result := malloc(2 + Len div 2);
PWord(Result)^ := HexToBin(Token, @Result[2], Len div 2);
end;
exports
bin_to_hex,
hex_to_bin;
begin
IsMultiThread := True;
end.
[Non-text portions of this message have been removed]
I tried to write the DLL below in Delphi/Windows. They worked fine, but i
found are some issues:
1) In your function 'bin_to_hex', you declare 'len' as longint, but as long
as only the first 2 bytes of an octet represents its length, maybe it should
be declared as word?
2) In your function 'hex_to_bin' it is missing 'cdecl; export;' in front of
it. Was it a typo or they are not required there?
3) I can use the UDF´s in FB only if i don´t use 'FREE_IT' in the function
declaration. If i use FREE_IT they crash the server (FB 2.1). Am i missing
something?
Regards,
Fabiano.
Here is my code:
library ps_udf;
uses
Classes,
SysUtils;
{$R *.res}
function malloc(Size: Integer): Pointer; cdecl; external 'msvcrt.dll';
function bin_to_hex(Token: PChar): PChar; cdecl; export;
var
Len: Word;
begin
Result := nil;
if Token = nil then
Exit;
Len := PWord(Token)^;
Result := malloc(Len * 2 + 1);
BinToHex(@Token[2], Result, Len);
Result[Len * 2] := #0;
end;
function hex_to_bin(Token: PChar): PChar; cdecl; export;
var
Len: LongWord;
begin
Result := nil;
if Token = nil then
Exit;
Len := StrLen(Token);
if Len mod 2 <> 0 then
Exit;
Result := malloc(2 + Len div 2);
PWord(Result)^ := HexToBin(Token, @Result[2], Len div 2);
end;
exports
bin_to_hex,
hex_to_bin;
begin
IsMultiThread := True;
end.
[Non-text portions of this message have been removed]