pb中使用winapi生成唯一的永不重復字符串(UUID)
2024-07-21 02:10:01
供稿:網友
1、定義結構及外部函數
global type uuid from structure ulong data1 uint data2 uint data3 character data4[8]end type
function ulong uuidcreate(ref uuid lpuuid) library "rpcrt4"function ulong uuidtostring (ref uuid lpuuid, ref long lpuuidstring) library "rpcrt4" alias for "uuidtostringa"function ulong rpcstringfree(long lpuuidstring) library "rpcrt4" alias for "rpcstringfreea"
2、函數主體
constant long rpc_s_ok = 0constant long rpc_s_uuid_local_only = 1824
long ll_rtnuuid ull_rtn = uuidcreate(u) //create a new uuidif 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_uuidelse return ""end if
注:發布時候可能需要rpcrt4.dll
附:另外一種生成guid的方法
oleobject pbobjectstring ls_guidlong ll_result
pbobject = create oleobject
ll_result = pbobject.connecttonewobject & ("powerbuilder.application")if ll_result < 0 then messagebox("","連接失敗:與powerbuilder.application連接出錯!") destroy pbobject return ""else ll_result = pbobject.generateguid(ref ls_guid)end ifdestroy pbobject
return mid(ls_guid,2,len(ls_guid) - 2)
第二種方法在程序發布時候需要在客戶端進行配置:
pbapl80.dllpbaen80.tlbrpcrt4.dll
修改注冊表如下
windows registry editor version 5.00
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; pbappl.reg;; registration information for powerbuilder.application.8;; all rights reserved. no portion of this material may be copied in any way; without prior written consent from powersoft corporation.;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; version independent progid entries
[hkey_classes_root/powerbuilder.application]@="powerbuilder automation"
[hkey_classes_root/powerbuilder.application/clsid]@="{88880001-8888-1000-8000-080009ac61a9}"
[hkey_classes_root/powerbuilder.application/curver]@="powerbuilder.application.8"
[hkey_classes_root/powerbuilder.application/notinsertable]@=""
; version specific progid entries[hkey_classes_root/powerbuilder.application.8]@="powerbuilder 8.0 automation"
[hkey_classes_root/powerbuilder.application.8/clsid]@="{88880001-8888-1000-8000-080009ac61a9}"
[hkey_classes_root/powerbuilder.application.8/notinsertable]@=""
; clsid entries[hkey_classes_root/clsid/{88880001-8888-1000-8000-080009ac61a9}]@="powerbuilder automation"
[hkey_classes_root/clsid/{88880001-8888-1000-8000-080009ac61a9}/inprocserver32]@="d://program files/ ybase/ hared//powerbuilder//pbvm80.dll""threadingmodel"="apartment"
[hkey_classes_root/clsid/{88880001-8888-1000-8000-080009ac61a9}/notinsertable]@=""
[hkey_classes_root/clsid/{88880001-8888-1000-8000-080009ac61a9}/progid]@="powerbuilder.application.8"
[hkey_classes_root/clsid/{88880001-8888-1000-8000-080009ac61a9}/programmable]@=""
[hkey_classes_root/clsid/{88880001-8888-1000-8000-080009ac61a9}/typelib]@="{88880002-8888-1000-8000-080009ac61a9}"
[hkey_classes_root/clsid/{88880001-8888-1000-8000-080009ac61a9}/versionindependentprogid]@="powerbuilder.application"
; type library registration entries[hkey_classes_root/typelib/{88880002-8888-1000-8000-080009ac61a9}]
[hkey_classes_root/typelib/{88880002-8888-1000-8000-080009ac61a9}/1.0]@="powerbuilder automation type library"
[hkey_classes_root/typelib/{88880002-8888-1000-8000-080009ac61a9}/1.0/0]
[hkey_classes_root/typelib/{88880002-8888-1000-8000-080009ac61a9}/1.0/0/win32]@="d://program files/ ybase/ hared//powerbuilder//pbaen80.tlb"
[hkey_classes_root/typelib/{88880002-8888-1000-8000-080009ac61a9}/1.0/9]
[hkey_classes_root/typelib/{88880002-8888-1000-8000-080009ac61a9}/1.0/9/win32]@="d://program files/ ybase/ hared//powerbuilder//pbaen80.tlb"