It is currently Sat Jun 06, 2020 2:06 am

All times are UTC + 1 hour




Post new topic Reply to topic  [ 9 posts ] 
Author Message
 Post subject: Create GUID via WinAPI
PostPosted: Sat Jul 09, 2005 1:49 pm 
Offline
User
User

Joined: Sat Nov 08, 2003 10:29 am
Posts: 60
Location: Austria
Code updated for 5.20+

Code:
; Uses aXends 'COMLIB' userlib!
;
; If  'COMLIB' is not available use the following
; Uni2Ansi-Procedure ((c) aXend):
;
 Procedure.s Uni2Ansi(*Unicode)
   size.l = WideCharToMultiByte_(#CP_ACP, 0, *Unicode, -1, #Null, #Null, #Null, #Null)
   ansi.s=Space(size)
   WideCharToMultiByte_(#CP_ACP, 0, *Unicode, -1, @ansi, size, #Null, #Null)
   ProcedureReturn ansi
 EndProcedure


Procedure.s GUIDcreate()
  g.GUID
  If CoCreateGuid_(@g) = #S_OK
    unicodeGUID$ = Space(78)
    GUIDLen = StringFromGUID2_(g, @unicodeGUID$, Len(unicodeGUID$))
   
    CompilerIf #PB_Compiler_Unicode
      ansiGUID$ = unicodeGUID$
    CompilerElse
      ansiGUID$ = Left(Uni2Ansi(@unicodeGUID$), GUIDLen-1)
    CompilerEndIf
  EndIf
ProcedureReturn ansiGUID$
EndProcedure

Debug GUIDcreate()


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Sat Jul 09, 2005 3:00 pm 
Offline
Addict
Addict
User avatar

Joined: Thu Aug 07, 2003 7:01 pm
Posts: 3141
Location: United Kingdom
Whats this for?

_________________
https://deluxepixel.com <- My Business website
https://reportcomplete.com <- School end of term reports system


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Sun Jul 10, 2005 11:28 am 
Offline
User
User

Joined: Sat Nov 08, 2003 10:29 am
Posts: 60
Location: Austria
GUID stands for Globally Unique Identifier. It's the Microsoft version of an UUID (Universally Unique Identifier). The GUID is a 128bit number given in the following format:

Code:
{xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx}

e.g. {E217B7A4-66C9-4E00-A962-78A20C1B484F}


Because of the 128 bits and the way the number is generated it is not very likely to find the same number twice on earth (therefore 'Globally Unique').
Windows uses GUIDs mostly in the context of COM objects as class- or interface identifier (e.g CLSID). But GUIDs can also be used as primary keys in databases, etc.

Just a few links:

http://www.webopedia.com/TERM/G/GUID.html
http://en.wikipedia.org/wiki/UUID


Last edited by javabean on Sun Jul 10, 2005 12:00 pm, edited 1 time in total.

Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Sun Jul 10, 2005 11:45 am 
Offline
Addict
Addict
User avatar

Joined: Thu Aug 07, 2003 7:01 pm
Posts: 3141
Location: United Kingdom
Thanks, that clears it up :)

-Anthony

_________________
https://deluxepixel.com <- My Business website
https://reportcomplete.com <- School end of term reports system


Top
 Profile  
Reply with quote  
 Post subject: Re: Create GUID via WinAPI
PostPosted: Sun Jan 26, 2020 10:59 pm 
Offline
New User
New User

Joined: Sat Dec 28, 2019 4:26 pm
Posts: 7
Much thanks for this


Top
 Profile  
Reply with quote  
 Post subject: Re: Create GUID via WinAPI
PostPosted: Mon Jan 27, 2020 1:33 am 
Offline
Enthusiast
Enthusiast

Joined: Thu Apr 18, 2019 8:17 am
Posts: 790
Cross-platform and only two lines of code:

Code:
For n=1 To 32 : t$+Hex(Random($F)) : Next
Debug Left(t$,8)+"-"+Mid(t$,9,4)+"-"+Mid(t$,13,4)+"-"+Mid(t$,17,4)+"-"+Mid(t$,21)

As a cross-platform procedure:

Code:
Procedure.s CreateGUID()
  For n=1 To 32 : t$+Hex(Random($F)) : Next
  ProcedureReturn Left(t$,8)+"-"+Mid(t$,9,4)+"-"+Mid(t$,13,4)+"-"+Mid(t$,17,4)+"-"+Mid(t$,21)
EndProcedure

Debug CreateGUID() ; 2AD0672A-55EA-CF01-1B0C-3613AB9274D7


Top
 Profile  
Reply with quote  
 Post subject: Re: Create GUID via WinAPI
PostPosted: Mon Jan 27, 2020 2:49 pm 
Offline
Addict
Addict
User avatar

Joined: Fri May 12, 2006 6:51 pm
Posts: 2489
Location: Germany
Random is not Safe...

Link for All OS: viewtopic.php?f=12&t=74015

_________________
My Projects ThreadToGUI / OOP-BaseClass / OOP-BaseClassDispatch / EventDesigner V3
PB v3.30 / v5.70 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace


Top
 Profile  
Reply with quote  
 Post subject: Re: Create GUID via WinAPI
PostPosted: Mon Jan 27, 2020 3:14 pm 
Offline
Addict
Addict
User avatar

Joined: Tue Mar 02, 2004 1:20 pm
Posts: 1116
Location: Amphibios 9
Code:
EnableExplicit

Procedure.s GetGUID()
 
  Protected *Buffer
  Protected GUID.s
 
  InitNetwork()
 
  *Buffer = ReceiveHTTPMemory("https://www.uuidgenerator.net/api/guid")
 
  If *Buffer
    GUID = PeekS(*Buffer, MemorySize(*Buffer), #PB_UTF8 | #PB_ByteLength)
    FreeMemory(*Buffer)
  Else
    Debug "Failed"
  EndIf
 
  ProcedureReturn GUID
 
EndProcedure

Debug GetGUID()


:P

_________________
Can't decide if i need a hug, an XXL coffee, 6 shots of vodka or 2 weeks of sleep.


Top
 Profile  
Reply with quote  
 Post subject: Re: Create GUID via WinAPI
PostPosted: Mon Jan 27, 2020 3:15 pm 
Offline
Enthusiast
Enthusiast
User avatar

Joined: Sun Sep 11, 2016 2:17 pm
Posts: 650
^^
Another (safe) one (x64 only!):

Code:
Procedure.s CreateGUID()
  Protected ps.i
  Protected gs.s
  If OpenCryptRandom()
    For ps = 0 To 35
      gs + Hex(CryptRandom($F))
    Next
    ps = @gs
    !mov rax,[p.v_ps]
    !mov word[rax + 0x10],0x2D
    !mov word[rax + 0x1A],0x2D
    !mov word[rax + 0x24],0x2D
    !mov word[rax + 0x2E],0x2D
    CloseCryptRandom()
  EndIf
  ProcedureReturn gs
EndProcedure


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 9 posts ] 

All times are UTC + 1 hour


Who is online

Users browsing this forum: No registered users and 11 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  

 


Powered by phpBB © 2008 phpBB Group
subSilver+ theme by Canver Software, sponsor Sanal Modifiye