 |
AutoHotkey Community Let's help each other out
|
| View previous topic :: View next topic |
| Author |
Message |
SKAN
Joined: 26 Dec 2005 Posts: 5887
|
Posted: Tue Jan 16, 2007 12:14 pm Post subject: |
|
|
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 |
 |
|
| Back to top |
|
 |
PhiLho
Joined: 27 Dec 2005 Posts: 6721 Location: France (near Paris)
|
Posted: Tue Jan 16, 2007 12:33 pm Post subject: |
|
|
| 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 |
|
 |
majkinetor
Joined: 24 May 2006 Posts: 3626 Location: Belgrade
|
Posted: Tue Jan 16, 2007 12:53 pm Post subject: |
|
|
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. I modified Philhose GetAnsiStringFromUnicodePointer function ... _________________
 |
|
| Back to top |
|
 |
Laszlo
Joined: 14 Feb 2005 Posts: 4016 Location: Pittsburgh
|
Posted: Tue Jan 16, 2007 3:42 pm Post subject: |
|
|
| look here, too. |
|
| Back to top |
|
 |
majkinetor
Joined: 24 May 2006 Posts: 3626 Location: Belgrade
|
Posted: Tue Jan 16, 2007 4:07 pm Post subject: |
|
|
thx _________________
 |
|
| Back to top |
|
 |
olfen
Joined: 04 Jun 2005 Posts: 99 Location: Stuttgart, Germany
|
Posted: Sat Sep 22, 2007 12:06 am Post subject: |
|
|
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 |
|
 |
|
|
You can post new topics in this forum You can reply to topics in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|