; 创建一个新的UUID(通用唯一标识符)。
MsgBox % CreateUUID() ; ==> xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx
; 创建GUID(全局唯一标识符),一个用于CLSID和接口标识符的128位唯一整数。
MsgBox % CreateGUID() ; ==> {XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX}
CreateUUID() {
VarSetCapacity(UUID, 16, 0)
if (DllCall("rpcrt4.dll\UuidCreate", "ptr", &UUID) != 0)
throw Exception("UuidCreate", -1)
if (DllCall("rpcrt4.dll\UuidToString", "ptr", &UUID, "uint*", suuid) != 0)
throw Exception("UuidToString", -1)
return StrGet(suuid), DllCall("rpcrt4.dll\RpcStringFree", "uint*", suuid)
}
CreateGUID() {
VarSetCapacity(pguid, 16, 0)
if (DllCall("ole32.dll\CoCreateGuid", "ptr", &pguid) != 0)
throw Exception("CoCreateGuid", -1)
size := VarSetCapacity(sguid, 38 * (A_IsUnicode ? 2 : 1) + 1, 0)
if !(DllCall("ole32.dll\StringFromGUID2", "ptr", &pguid, "ptr", &sguid, "int", size))
throw Exception("StringFromGUID2", -1)
return StrGet(&sguid)
}
声明:站内资源为整理优化好的代码上传分享与学习研究,如果是开源代码基本都会标明出处,方便大家扩展学习路径。请不要恶意搬运,破坏站长辛苦整理维护的劳动成果。本站为爱好者分享站点,所有内容不作为商业行为。如若本站上传内容侵犯了原著者的合法权益,请联系我们进行删除下架。

评论(0)