1. Rick Wolfgang
  2. PowerBuilder
  3. Monday, 6 January 2020 15:42 PM UTC

I am having trouble creating a GUID on my executable.

It works fine in development but it fails when I run it on an executable on any machine that I do not have

PB installed.

 

OLEObject myoleobject

myoleobject = CREATE OLEObject

PBObject = CREATE oleObject
ll_result = PBObject.ConnectToObject &
("PowerBuilder.Application")
ll_result = PBObject.ConnectToNewObject &
("PowerBuilder.Application")

ll_result = PBObject.GenerateGUID(REF ls_GUID)  //this is where it fails on the executable.

 

I do have the rtcrt4.dll  in the path.   When i try it in an older version of powerbuilder I get a -2 result.

Chris Pollach @Appeon Accepted Answer Pending Moderation
  1. Monday, 6 January 2020 18:05 PM UTC
  2. PowerBuilder
  3. # 1

Hi Rick;

  Looks like you are using the old and deprecated PBObject avenue from the PB version 11.x days.

Suggestion#1: How about using your DBMS's internal methods for generating GUID's ... for example:

Oracle: SYS_GUID()
SQL Server: NEWID()
Adaptive Sever Anywhere: NEWID()

Suggestion#2:  Roland has some great native PB Based GUID generator code in his SMTP example ...

FYI: http://www.topwizprogramming.com/freecode_emailsmtp.html

HTH

Regards ... Chris

 

Comment
There are no comments made yet.
Sivaprakash BKR Accepted Answer Pending Moderation
  1. Tuesday, 7 January 2020 07:43 AM UTC
  2. PowerBuilder
  3. # 2

Here is the required function to generate UUID in powerbuilder

// External function

FUNCTION long uuidCreate(ref sr_uuid astr_uuid) LIBRARY "Rpcrt4.dll" ALIAS FOR "UuidCreate"

 

// Function to generate UUID

Function of_generate_uuid(string as_type)
Long ll_rc
sr_uuid lstr_uuid
string ls_guid = ""

constant long RPC_S_OK = 0
constant long RPC_S_UUID_LOCAL_ONLY = 1824
constant long RPC_S_UUID_NO_ADDRESS = 1739

ll_rc = uuidCreate(lstr_uuid)

IF ll_rc <> RPC_S_OK THEN
setNull(ls_GUID)
ELSE
If as_type = 'F' Then
ls_GUID = right("00000000" + of_tohex(lstr_uuid.data1), 8)
ls_GUID += "-" + right("0000" + of_tohex(lstr_uuid.data2), 4)
ls_GUID += "-" + right("0000" + of_tohex(lstr_uuid.data3), 4)
ls_GUID += "-" + right("0000" + of_tohex(lstr_uuid.data4[1]), 4)
ls_GUID += "-" + right("0000" + of_tohex(lstr_uuid.data4[2]), 4) &
+ right("0000" + of_tohex(lstr_uuid.data4[3]), 4) &
+ right("0000" + of_tohex(lstr_uuid.data4[4]), 4)
ls_GUID = upper(ls_GUID)
// output example : 00003B93-2641-477A-C99E-A2FFEBEB214A
Elseif as_type = 'R' Then
ls_GUID = right("00000000" + of_tohex(lstr_uuid.data1), 8)
ls_GUID += right("0000" + of_tohex(lstr_uuid.data2), 4)
ls_GUID += right("0000" + of_tohex(lstr_uuid.data3), 4)
ls_GUID += right("0000" + of_tohex(lstr_uuid.data4[1]), 4)
ls_GUID += right("0000" + of_tohex(lstr_uuid.data4[2]), 4) &
+ right("0000" + of_tohex(lstr_uuid.data4[3]), 4) &
+ right("0000" + of_tohex(lstr_uuid.data4[4]), 4)
ls_GUID = upper(ls_GUID)
// output example : 00003B932641477AC99EA2FFEBEB214A
End If
End If

Return ls_guid

// How to call

String    ls_uuid
ls_uuid = of_generate_uuid('R')              // Returns 00003B932641477AC99EA2FFEBEB214A
ls_uuid = of_generate_uuid('F')             // Returns 00003B93-2641-477A-C99E-A2FFEBEB214A

It works from PB 10.5, PB 11.5 & PB 2017 R3, which I've tested.

Happiness Always
BKR Sivaprakash

 

Comment
There are no comments made yet.
  • Page :
  • 1


There are no replies made for this question yet.
However, you are not allowed to reply to this question.