首页 > 开发 > 综合 > 正文

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"
发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表