A small module created from a small utility program created by ts-soft.
Best regards
StarBootics
Code: Select all
; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
; Project name : GUID Generator
; File Name : GUID Generator - Module.pb
; File version: 1.1.0
; Programming : OK
; Programmed by : StarBootics
; Date : 27-01-2016
; Last Update : 27-01-2016
; PureBasic code : V5.41 LTS
; Platform : Windows, Linux, MacOS X
; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
; Notes
;
; This code is an excerpt from the GUID Generator
; tiny tool for PB IDE created by ts-soft
; (english and german forum)
;
; I deserve credit only to convert the original
; code into a Module.
;
; This code is free to be use where ever you like
; but you use it at your own risk.
;
; The author can in no way be held responsible
; for data loss, damage or other annoying
; situations that may occur.
;
; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
DeclareModule GUID
Declare.s Make(Wrap_With_Brackets.b = #False)
EndDeclareModule
Module GUID
CompilerIf Defined(GUID, #PB_Structure) = #False
Structure GUID
Data1.l
Data2.w
Data3.w
Data4.b[8]
EndStructure
CompilerEndIf
CompilerIf #PB_Compiler_OS = #PB_OS_Linux
; requires uuid-dev (sudo apt-get install uuid-dev)
ImportC "-luuid"
uuid_generate(*generated.GUID)
uuid_unparse_upper(*uu.GUID, *out)
EndImport
CompilerEndIf
Procedure.s Make(Wrap_With_Brackets.b = #False)
Protected guid.GUID, result.s
CompilerSelect #PB_Compiler_OS
CompilerCase #PB_OS_Linux
result = Space(36)
uuid_generate(@guid)
uuid_unparse_upper(@guid, @result)
If Wrap_With_Brackets = #True
result = "{" + PeekS(@result, -1, #PB_Ascii) + "}"
Else
result = PeekS(@result, -1, #PB_Ascii)
EndIf
CompilerCase #PB_OS_Windows
Protected lpsz.s{78}
If CoCreateGuid_(@guid) = #S_OK
result = PeekS(@lpsz, StringFromGUID2_(guid, @lpsz, 76), #PB_Unicode)
If Wrap_With_Brackets = #False
result = RemoveString(RemoveString(result, "}"), "{")
EndIf
EndIf
CompilerDefault ; #PB_OS_MacOS
For Index = 0 To 15
If Index = 7
Byte.a = 64 + Random(15)
ElseIf Index = 9
Byte = 128 + Random(63)
Else
Byte = Random(255)
EndIf
If Index = 4 Or Index = 6 Or Index = 8 Or Index = 10
result.s + "-"
EndIf
result + RSet(Hex(Byte),2,"0")
Next
If Wrap_With_Brackets = #True
result = "{" + result + "}"
EndIf
CompilerEndSelect
ProcedureReturn result
EndProcedure
EndModule
CompilerIf #PB_Compiler_IsMainFile
For Index = 0 To 99
Debug GUID::Make()
Next
CompilerEndIf
; <<<<<<<<<<<<<<<<<<<<<<<
; <<<<< END OF FILE <<<<<
; <<<<<<<<<<<<<<<<<<<<<<<