AutoHotkey Homepage AutoHotkey Community
Let's help each other out
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Universally Unique Identifier (UUID/GUID) Generator
Goto page Previous  1, 2
 
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Scripts & Functions
View previous topic :: View next topic  
Author Message
SKAN



Joined: 26 Dec 2005
Posts: 5887

PostPosted: Tue Jan 16, 2007 12:14 pm    Post subject: Reply with quote

Here .. this seems to work:

Code:
VarSetCapacity(bGuid, 16,0)
VarSetCapacity(sGuid, 76)

dllcall("ole32.dll\CoCreateGuid", uint,  &bGuid)
x := dllcall("ole32.dll\StringFromGUID2", "uint", &bGuid, "str", sGuid, "int", 76)

Loop 76
 UUID .= (Mod(A_Index,2) = 1) ? Chr( *(&sGuid+(A_Index-1)) ) : ""

msgbox % UUID


Smile
Back to top
View user's profile Send private message
PhiLho



Joined: 27 Dec 2005
Posts: 6721
Location: France (near Paris)

PostPosted: Tue Jan 16, 2007 12:33 pm    Post subject: Reply with quote

Skan wrote:
I think Random command should be available as a function.
Most of such commands (with OutputVar) will become functions in v.2.

majkinetor: thanks for the research. Usable code:
Code:
VarSetCapacity(binGuid, 16) ; 128 bits
guidSize = 40   ; Slight oversize
VarSetCapacity(uniGuid, guidSize * 2)
DllCall("Ole32.dll\CoCreateGuid", "UInt", &binGuid)
bytes := DllCall("Ole32.dll\StringFromGUID2"
      , "UInt", &binGuid
      , "UInt", &uniGuid
      , "Int", guidSize * 2)
;~ MsgBox % DumpDWORDs(uniGuid, 80, true)
VarSetCapacity(ansiGuid, guidSize)
DllCall("WideCharToMultiByte"
      , "UInt", 0        ; CodePage: CP_ACP=0 (current Ansi), CP_UTF7=65000, CP_UTF8=65001
      , "UInt", 0        ; dwFlags
      , "UInt", &uniGuid ; LPCWSTR lpWideCharStr
      , "Int", guidSize  ; cchWideChar: size in WCHAR values, -1=null terminated
      , "Str", ansiGuid  ; LPSTR lpMultiByteStr
      , "Int", guidSize  ; cbMultiByte: 0 to get required size
      , "UInt", 0        ; LPCSTR lpDefaultChar
      , "UInt", 0)       ; LPBOOL lpUsedDefaultChar
MsgBox %bytes% %ansiGuid%

_________________
vPhiLho := RegExReplace("Philippe Lhoste", "^(\w{3})\w*\s+\b(\w{3})\w*$", "$1$2")
Back to top
View user's profile Send private message Visit poster's website
majkinetor



Joined: 24 May 2006
Posts: 3626
Location: Belgrade

PostPosted: Tue Jan 16, 2007 12:53 pm    Post subject: Reply with quote

This is the function:

Code:
msgbox % CreateGUID()

CreateGuid()
{
   local len, ansiString, data

   VarSetCapacity(data, 96)

   dllcall("ole32.dll\CoCreateGuid", "uint", &data)
   dllcall("ole32.dll\StringFromGUID2", "uint", &data, "str", data, "int", 40)

   len := DllCall("lstrlenW", "UInt", &data)
   VarSetCapacity(ansiString, len, 0)

   DllCall("WideCharToMultiByte"
         , "UInt", 0         ; CodePage: CP_ACP=0 (current Ansi), CP_UTF7=65000, CP_UTF8=65001
         , "UInt", 0         ; dwFlags
         , "UInt", &data      ; LPCWSTR lpWideCharStr
         , "Int", len         ; cchWideChar: size in WCHAR values, -1=null terminated
         , "Str", ansiString   ; LPSTR lpMultiByteStr
         , "Int", len         ; cbMultiByte: 0 to get required size
         , "UInt", 0         ; LPCSTR lpDefaultChar
         , "UInt", 0)         ; LPBOOL lpUsedDefaultChar

   Return ansiString
}


Ah... I went to lunch before posting this and I see that you already did this code. Very Happy I modified Philhose GetAnsiStringFromUnicodePointer function ...
_________________
Back to top
View user's profile Send private message MSN Messenger
Laszlo



Joined: 14 Feb 2005
Posts: 4016
Location: Pittsburgh

PostPosted: Tue Jan 16, 2007 3:42 pm    Post subject: Reply with quote

look here, too.
Back to top
View user's profile Send private message
majkinetor



Joined: 24 May 2006
Posts: 3626
Location: Belgrade

PostPosted: Tue Jan 16, 2007 4:07 pm    Post subject: Reply with quote

thx
_________________
Back to top
View user's profile Send private message MSN Messenger
olfen



Joined: 04 Jun 2005
Posts: 99
Location: Stuttgart, Germany

PostPosted: Sat Sep 22, 2007 12:06 am    Post subject: Reply with quote

Just for the record: Generate a GUID via COM (needs Sean's Standard Library COM.ahk)
Code:
CreateGUID()
{
  local pST, pGUID, sGUID
  COM_CoInitialize()
  pST := COM_ActiveXObject("Scriptlet.TypeLib")
  DllCall(COM_VTable(pST, 21), "Uint", pST, "UIntP", pGUID)
  COM_Unicode2Ansi(pGUID, sGUID)
  COM_SysFreeString(pGUID)
  COM_CoUninitialize()
  Return sGUID
}
Back to top
View user's profile Send private message Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Scripts & Functions All times are GMT
Goto page Previous  1, 2
Page 2 of 2

 
Jump to:  
You can post new topics in this forum
You can reply to topics in this forum


Powered by phpBB © 2001, 2005 phpBB Group