Returning a GUID to OI (OpenInsight 32-bit Specific)
At 31 MAR 2008 01:42:29AM James wrote:
Hi all
Has anyone created a new GUID from within OI? I thought I'd have a go today, but am not having much luck.
I'm running OI 8.0.1 on XP, Sp2
The OLE32.DLL version is 5.1.2600.2726, if that helps.
1. Prototype Defintion 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)
short (2 bytes)
short (2 bytes)
char(8) (8 bytes)
3. Testing source code:
subroutine test_guid(void)
Declare Subroutine CoInitialize, CoUnInitialize, parse_struct
Declare Function CoCreateGuid, blank_struct
equ guid_ok$ to 0
CoInitialize(0)
Guid=blank_struct('GUID')
pGuid=GetPointer(Guid)
retval=CoCreateGuid(pGuid) ;*-] returns 87!? should have been 0
if retval=guid_ok$ then
Parse_Struct(Guid, 'GUID', 1st_part, 2nd_part, 3rd_part, 4th_part)end
CoUnInitialize()
return
TIA for any thoughts.
At 31 MAR 2008 10:03PM James wrote:
Wow.. and today error codes… :) I did change the DLL defintion to what I put on the previous post.. perhaps it only takes effect upon new login?
I'm using the following code, it *seems* ok.
Main routine
function get_guid(void)
* 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
* custom
declare function fill_leading
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=fill_leading(oconv(a,'MX'),0,8)part2=fill_leading(oconv(b,'MX'),0,4)part3=fill_leading(oconv(c,'MX'),0,4)
convert char array to hex representationshex_chars='for idx=1 to len(d) ;* should be 8hex_chars := fill_leading(oconv(seq(didx,1),'MX'),'0',2)next idxpart4=hex_chars1,4part5=hex_chars5,9
combine into GUID formatretGuid={':part1:'-':part2:'-':part3:'-':part4:'-':part5:'}'end
CoUnInitialize()
return retGuid
utility routine
function fill_leading(aSourceStr, aFillChar, aNewLength)
current_length=len(aSourceStr)
if (aNewLength ] current_length) then
return str(aFillChar, aNewLength - current_length):aSourceStrend else if (aNewLength < current_length) then
return aSourceStr1,aNewLength ;* NB - will truncate!end else
return aSourceStrend
return
And I just realised the Works board is heaps more active. Oh well.. next time :)
At 01 APR 2008 02:13AM [url=http://www.sprezzatura.com]The Sprezzatura Group[/url] wrote:
Guessing Fill_leading is === to Fmt(Var, "R(0)#8")?
World leaders in all things RevSoft
At 01 APR 2008 08:00PM James wrote:
yep :)
Hmmm.. memory isn't what it used to be.
At 03 APR 2008 05:49PM James wrote:
Just incase anyone is trying similar, here's the working version thanks to feedback from Matt + Sprezz.
function get_guid(void) * Returns a unique GUID value as a string, or empty upon failure * Ole32 dll calls declare subroutine CoInitialize, CoUnInitialize declare function CoCreateGuid * system $insert logical declare subroutine parse_struct, setUTF8 declare function blank_struct, GetByteSize, isUTF8 * const equ guid_ok$ to 0 equ pad_char$ to '0' equ is_utf$ to isUTF8() gosub initialise retval=CoCreateGuid(stGuid) if retval=guid_ok$ then gosub create_guid end gosub finalise return retGuid ** end ******* initialise: retGuid=' CoInitialize(0) stGuid=blank_struct('GUID') * we must be in ANSI mode so the char array can be iterated correctly if is_utf$ then SetUTF8(false$) end return create_guid: Parse_Struct(stGuid, 'GUID', a, b, c, d) part1=fmt(oconv(a,'MX'),'R(':pad_char$:')#8') part2=fmt(oconv(b,'MX'),'R(':pad_char$:')#4') part3=fmt(oconv(c,'MX'),'R(':pad_char$:')#4') * convert each char -] ansi -] hex hex_chars=' no_of_chars=GetByteSize(d) for idx=1 to no_of_chars ;* should be 8! hex_chars := fmt(oconv(seq(didx,1),'MX'),'R(':pad_char$:')#2') next idx part4=hex_chars1,4 part5=hex_chars5,12 * combine into GUID format retGuid={':part1:'-':part2:'-':part3:'-':part4:'-':part5:'}' return finalise: CoUnInitialize() if is_utf$ then SetUTF8(true$) end return