libuuid.pp 1.1 KB

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