{{tag>category:"OpenInsight 32-Bit" author:"Karl Pozmann" author:"Jared Bratu" author:"Barry Stevens"}} [[https://www.revelation.com/the-works|Join The Works program to have access to the most current content, and to be able to ask questions and get answers from Revelation staff and the Revelation community]] ==== GUID Creation (OpenInsight 32-Bit) ==== === At 22 APR 2010 04:02:05PM Karl Pozmann wrote: === Anyone have a utility to generate a GUID? I've read about the various algorithms utilizing IP addresses, etc but I thought I would start here and not reinvent the wheel. ---- === At 22 APR 2010 05:02PM Jared Bratu wrote: === OpenInsight 9.0+ include a function RTI_CREATEGUID. It uses the windows API to return a standard GUID. Try this code snippet: Declare Function RTI_CreateGuid MyGuid=RTI_CreateGuid() ---- === At 22 APR 2010 06:57PM Barry Stevens wrote: === If you are not using 9.0+, then the following may help: Obtained and refined from forum search - GUID function bsbs_get_guid(void) /******************INITIAL SETUP STEPS************************************ ************************************************************************** 1. Prototype Definition called DLL_OLE32: OLE32 VOID STDCALL CoInitialize(LPCHAR) INT STDCALL CoCreateGuid(LPCHAR) VOID STDCALL CoUninitialize() 2. Created a structure using DEFINE_STRUCT form called "GUID": unsigned long (4 bytes) unsigned short (2 bytes) unsigned short (2 bytes) char(8) (8 bytes) ************************************************************************/ ************************************************************************ * Returns a unique GUID value as a string, or empty upon failure * Ole32 dll calls declare subroutine CoInitialize, CoUnInitialize declare function CoCreateGuid * system declare subroutine parse_struct declare function blank_struct equ guid_ok$ to 0 retGuid=' CoInitialize(0) stGuid=blank_struct('GUID') retval=CoCreateGuid(stGuid) if retval=guid_ok$ then Parse_Struct(stGuid, 'GUID', a, b, c, d) part1=oconv(a,'MX') part2=oconv(b,'MX') part3=oconv(c,'MX') part1=Fmt(part1, "R(0)#8") part2=Fmt(part2, "R(0)#4") part3=Fmt(part3, "R(0)#4") * convert char array to hex representations hex_chars=' for idx=1 to len(d) ;* should be 8 *hex_chars := fill_leading(oconv(seq(didx,1),'MX'),'0',2) hex_chars := fmt(oconv(seq(didx,1),'MX'),"R(0)#2") next idx part4=hex_chars1,4 part5=hex_chars5,9 * combine into GUID format retGuid={':part1:'-':part2:'-':part3:'-':part4:'-':part5:'}' end CoUnInitialize() return retGuid **** ---- === At 23 APR 2010 05:47AM Karl Pozmann wrote: === Very cool - I knew up front there was a lot more to this seemingly simple task. And you were correct in that this is for a OI 7.2 app. Many thanks! ---- === At 23 APR 2010 07:39AM Karl Pozmann wrote: === Thanks again, Barry. I copied and setup everything and in the end it looks like part5 is null. I setup the struct as a POINT. Here is the test program I ran which returned "{CD774E21-6783-49F9-BB-}": Function GUID_Test() * Returns a unique GUID value as a string, or empty upon failure * Ole32 dll calls declare subroutine CoInitialize, CoUnInitialize declare function CoCreateGuid * system declare subroutine parse_struct declare function blank_struct equ guid_ok$ to 0 retGuid=' CoInitialize(0) stGuid=blank_struct('GUID') retval=CoCreateGuid(stGuid) if retval=guid_ok$ then Parse_Struct(stGuid, 'GUID', a, b, c, d) part1=oconv(a,'MX') part2=oconv(b,'MX') part3=oconv(c,'MX') part1=Fmt(part1, "R(0)#8") part2=Fmt(part2, "R(0)#4") part3=Fmt(part3, "R(0)#4") * convert char array to hex representations hex_chars=' for idx=1 to len(d) ;* should be 8 *hex_chars := fill_leading(oconv(seq(didx,1),'MX'),'0',2) hex_chars := fmt(oconv(seq(didx,1),'MX'),"R(0)#2") next idx part4=hex_chars1,4 part5=hex_chars5,9 * combine into GUID format retGuid={':part1:'-':part2:'-':part3:'-':part4:'-':part5:'}' end CoUnInitialize() return retGuid [[https://www.revelation.com/revweb/oecgi4p.php/O4W_HANDOFF?DESTN=O4W_RUN_FORM&INQID=WORKS_READ&SUMMARY=1&KEY=C638391D89AB8AC68525770D006E0DE6|View this thread on the Works forum...]]