libuuid.pp 959 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. {$mode objfpc}
  2. {$H+}
  3. Unit Libuuid;
  4. interface
  5. uses SysUtils,dynlibs;
  6. Var
  7. LibUUIDName : String = 'libuuid.so.1';
  8. ProcName : String = 'uuid_generate_time';
  9. function CCreateGUID(out Guid: TGUID): Integer;
  10. Implementation
  11. Type
  12. TGenProc = procedure (out Guid: TGUID);cdecl;
  13. var
  14. Handle : TLibHandle;
  15. GenFunc : TGenProc;
  16. Function InitLibrary : Boolean;
  17. begin
  18. Result:=(Handle<>NilHandle);
  19. If Not result then
  20. begin
  21. Handle:=LoadLibrary(LibUUIDName);
  22. Result:=(Handle<>NilHandle);
  23. if Result then
  24. begin
  25. GenFunc:=TGenProc(GetProcedureAddress(Handle, ProcName));
  26. Result:=(GenFunc<>nil);
  27. end;
  28. end;
  29. end;
  30. function CCreateGUID(out Guid: TGUID): HResult;
  31. begin
  32. Result := -1;
  33. if InitLibrary then
  34. begin
  35. GenFunc(Guid);
  36. Result := 0;
  37. end;
  38. end;
  39. initialization
  40. If InitLibrary then
  41. OnCreateGUID:=@CCreateGUID;
  42. Finalization
  43. if (Handle<>NilHandle) then
  44. UnLoadLibrary(Handle)
  45. end.