pb中使用winapi生成全球唯一标示码(GUID,UUID) [pb8,pb11.5测试成功]
1、定义结构:global type uuid from structure
ulong data1
uint data2
uint data3
character data4
end type
2、定义外部函数:
PB9及以下:
Function ulong UuidCreate(ref uuid lpUUID) LIBRARY "rpcrt4"
Function ulong UuidToString (ref uuid lpUUID, ref long lpUUIDString)LIBRARY "rpcrt4" Alias for "UuidToStringA;Ansi"
Function ulong RpcStringFree(long lpUUIDString) LIBRARY "rpcrt4"Alias for "RpcStringFreeA"
PB10及以上:
Function ulong UuidCreate(ref uuid lpUUID) LIBRARY "rpcrt4" alias for "UuidCreate;Ansi"
Function ulong UuidToString (ref uuid lpUUID, ref long lpUUIDString)LIBRARY "rpcrt4" Alias for "UuidToStringW;Ansi"
Function ulong RpcStringFree(long lpUUIDString) LIBRARY "rpcrt4"Alias for "RpcStringFreeW"
3、函数主体:
//====================================================================
// 事件: .gs_get_guid()
//--------------------------------------------------------------------
// 描述:
//--------------------------------------------------------------------
// 参数:
//--------------------------------------------------------------------
// 返回:string
//====================================================================
CONSTANT LongRPC_S_OK = 0
CONSTANT LongRPC_S_UUID_LOCAL_ONLY = 1824
Long ll_rtn
uuid u
ll_rtn = uuidcreate(u)//Create a new UUID
IF ll_rtn = RPC_S_OK OR ll_rtn = RPC_S_UUID_LOCAL_ONLY THEN
Long ll_pointer
String ls_uuid
ll_rtn = UuidToString(u,ll_pointer)
ls_uuid = Upper(String (ll_pointer,"Address")) //Convert it to a string
RpcStringFree(ll_pointer)//Remove the string from the memory
RETURN ls_uuid
ELSE
RETURN ""
END IF
4、调用:
sle_1.text = gs_get_guid()
pb8,pb11.5测试成功
页:
[1]