summaryrefslogtreecommitdiff
path: root/packages/uuid/src/libuuid.pp
blob: 78fbd62b589c7ae287212a279617526ad86c5f44 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
{$mode objfpc}
{$H+}
Unit Libuuid;

interface

uses SysUtils,dynlibs;

Var
  LibUUIDName : String = 'libuuid.so.1';
  ProcName    : String = 'uuid_generate_time';
  
function CCreateGUID(out Guid: TGUID): HResult;

Implementation


Type
  TGenProc = procedure (out Guid: TGUID);cdecl;

var
  Handle : TLibHandle;
  GenFunc : TGenProc;

Function InitLibrary : Boolean;

begin
  Result:=(Handle<>NilHandle);
  If Not result then
    begin
    Handle:=LoadLibrary(LibUUIDName);
    Result:=(Handle<>NilHandle);
    if Result then
      begin
      GenFunc:=TGenProc(GetProcedureAddress(Handle, ProcName));
      Result:=(GenFunc<>nil);
      end;
    end;
end;


function CCreateGUID(out Guid: TGUID): HResult;

begin
  Result := -1;
  if InitLibrary then
    begin
    GenFunc(Guid);
    Result := 0;
    end;
end;


initialization
  If InitLibrary then
    OnCreateGUID:=@CCreateGUID;
Finalization
  if (Handle<>NilHandle)  then
    UnLoadLibrary(Handle)
end.