Browse Source

+ Implementation of CreateGUID

git-svn-id: trunk@27 -
michael 20 years ago
parent
commit
99658cf4d6

+ 2 - 0
rtl/objpas/sysutils/sysutilh.inc

@@ -171,6 +171,8 @@ type
    procedure Beep;
    function SysErrorMessage(ErrorCode: Integer): String;
 
+   Function  CreateGUID(out GUID : TGUID) : Integer;
+
 type
   TTerminateProc = Function: Boolean;
 

+ 21 - 0
rtl/objpas/sysutils/sysutils.inc

@@ -496,6 +496,27 @@ begin
     end;
 end;
 
+Procedure GetRandomBytes(Var Buf; NBytes : Integer);
+
+Var
+  I : Integer;
+  P : PByte;
+
+begin
+  P:=@Buf;
+  Randomize;
+  For I:=0 to NBytes-1 do
+    P[i]:=Random(256);
+end;
+
+
+{$IFNDEF HASCREATEGUID}
+Function CreateGUID(out GUID : TGUID) : Integer;
+begin
+  Result:=0;
+  GetRandomBytes(GUID,SizeOf(Guid));  
+end;
+{$ENDIF}
 
 {
   Revision 1.1  2003/10/06 21:01:06  peter

+ 7 - 0
rtl/unix/sysutils.pp

@@ -26,6 +26,7 @@ interface
 {$DEFINE HAS_OSCONFIG}
 {$DEFINE HAS_TEMPDIR}
 {$DEFINE HASUNIX}
+{$DEFINE HASCREATEGUID}
 
 uses
   Unix,errors,sysconst,Unixtype;
@@ -64,6 +65,11 @@ Type
 { Include platform independent implementation part }
 {$i sysutils.inc}
 
+{ Include CreateGUID function } 
+
+{$i uuid.inc}
+
+
 Const
 {Date Translation}
   C1970=2440588;
@@ -1089,6 +1095,7 @@ begin
     Result:=IncludeTrailingPathDelimiter(Result);
 end;
 
+
 {****************************************************************************
                               Initialization code
 ****************************************************************************}

+ 7 - 0
rtl/win32/sysutils.pp

@@ -36,6 +36,7 @@ uses
 {$DEFINE HAS_SLEEP}
 {$DEFINE HAS_OSERROR}
 {$DEFINE HAS_OSCONFIG}
+{$DEFINE HAS_CREATEGUID}
 { Include platform independent interface part }
 {$i sysutilh.inc}
 
@@ -64,7 +65,13 @@ implementation
 { Include platform independent implementation part }
 {$i sysutils.inc}
 
+function CoCreateGuid(out guid: TGUID): HResult; stdcall; external 'ole32.dll' name 'CoCreateGuid';
 
+function CreateGUID(out Guid: TGUID): HResult;
+begin
+  Result := CoCreateGuid(Guid);
+end;
+  
 {****************************************************************************
                               File Functions
 ****************************************************************************}