Old 13th August 2003, 19:34   #1
dselkirk
Senior Member
 
Join Date: Aug 2002
Posts: 118
Create a GUID, a Globally Unique Identifier

Creates a GUID, or Globally Unique Identifier. Thanks to everyone who helped with the hex and character array issues.

Supports: Win9x, WINNT, WIN2K and WINXP
Requires: System Plugin
Archive: http://nsis.sourceforge.net/archive/...74&instances=0

code:

;Call CreateGUID
;Pop $0 ;contains GUID
Function CreateGUID
Push $R0
Push $R1
Push $R2
Push $R3
Push $R4
;allocate space for character array
System::Alloc 15
;get pointer to new space
Pop $R1
;call the CoCreateGuid api in the ole32.dll
System::Call 'ole32::CoCreateGuid(i R1) i .R2'
;if 0 then continue
IntCmp $R2 0 0 lbl_done
;set counter to 0
StrCpy $R3 0
lbl_loop:
;increment counter
IntOp $R3 $R3 + 1
;if less than 16 then continue
IntCmp $R3 16 lbl_done 0 lbl_done
;retrieve item in character array
System::Call "*$R1(&t$R3-1, &i1 .R2)"
;convert to hex
IntFmt $R4 "%X" $R2
StrCpy $R4 "00$R4"
StrLen $R2 $R4
IntOp $R2 $R2 - 2
StrCpy $R4 $R4 2 $R2
StrCpy $R0 "$R0$R4"
Goto lbl_loop
lbl_done:
;cleanup
System::Free $R1
;format guid
StrCpy $R1 $R0
StrCpy $R0 ""
StrCpy $R2 $R1 8
StrCpy $R0 "$R0$R2-"
StrCpy $R2 $R1 4 8
StrCpy $R0 "$R0$R2-"
StrCpy $R2 $R1 4 12
StrCpy $R0 "$R0$R2-"
StrCpy $R2 $R1 4 16
StrCpy $R0 "$R0$R2-"
StrCpy $R2 $R1 12 20
StrCpy $R0 "$R0$R2"
Pop $R4
Pop $R3
Pop $R2
Pop $R1
Exch $R0
FunctionEnd

dselkirk is offline   Reply With Quote
Old 13th August 2003, 19:51   #2
Afrow UK
Moderator
 
Afrow UK's Avatar
 
Join Date: Nov 2002
Location: Surrey, England
Posts: 8,434
Works great!
Could you post it on the NSIS Archive for others.

Thanks

-Stu
Afrow UK is offline   Reply With Quote
Old 13th August 2003, 20:10   #3
Joost Verburg
NSIS MUI Dev
 
Join Date: Nov 2001
Posts: 3,717
He already did.
Joost Verburg is offline   Reply With Quote
Old 13th August 2003, 23:12   #4
brainsucker
Senior Member
 
brainsucker's Avatar
 
Join Date: Sep 2002
Location: Minsk, Belarus
Posts: 190
Send a message via ICQ to brainsucker
You actually need 16 bytes to be allocated for GUID (128 bit) (I meaning your system::alloc). The alternative way completely thru ole and kernel functions (string guid at $3):
System::Alloc 16
Pop $1
System::Alloc 80
Pop $2
System::Call 'ole32::CoCreateGuid(i r1) i'
System::Call 'ole32::StringFromGUID2(i r1, i r2, i 80) i'
System::Call 'kernel32::WideCharToMultiByte(i 0, i 0, i r2, i 80, t .r3, i ${NSIS_MAX_STRLEN}, i 0, i 0) i'
System::Free $1
System::Free $2
brainsucker is offline   Reply With Quote
Old 13th August 2003, 23:15   #5
brainsucker
Senior Member
 
brainsucker's Avatar
 
Join Date: Sep 2002
Location: Minsk, Belarus
Posts: 190
Send a message via ICQ to brainsucker
Oh A bit better look

System::Alloc 80
System::Alloc 16
System::Call 'ole32::CoCreateGuid(i sr1) i'
System::Call 'ole32::StringFromGUID2(i r1, i sr2, i 80) i'
System::Call 'kernel32::WideCharToMultiByte(i 0, i 0, i r2, i 80, t .r3, i ${NSIS_MAX_STRLEN}, i 0, i 0) i'
System::Free $1
System::Free $2
brainsucker is offline   Reply With Quote
Old 14th August 2003, 13:20   #6
dselkirk
Senior Member
 
Join Date: Aug 2002
Posts: 118
Thanks for the help brainsucker. I actually was going to use the stringfromguid2 api but I was under the impression that it wasn't support under Win9x. I've updated the archive entree with your better version. Thanks again.
dselkirk is offline   Reply With Quote
Old 17th August 2003, 20:12   #7
mrtech
Junior Member
 
Join Date: Oct 2002
Posts: 46
Talking

So will this function work with Win 9x machines? Does the archive need to be updated?
mrtech is offline   Reply With Quote
Old 17th August 2003, 21:51   #8
dselkirk
Senior Member
 
Join Date: Aug 2002
Posts: 118
I've tested it on 98, ME, NT, 2K and XP without any problems. I have already updated the archive with the new code.

Thanks
dselkirk is offline   Reply With Quote
Old 17th August 2003, 23:47   #9
Joel
Debian user
(Forum King)
 
Joel's Avatar
 
Join Date: Jan 2003
Location: Arch land
Posts: 4,917
good code dselkirk


* PC: Intel Core 2 DUO E6550 @ 2.33 GHz with 2 GB RAM: Archlinux-i686 with MATE.
* Laptop: Intel Core 2 DUO T6600 @ 2.20 GHz with 4 GB RAM: Archlinux-x86-64 with MATE.
Joel is offline   Reply With Quote
Old 18th August 2003, 12:54   #10
dselkirk
Senior Member
 
Join Date: Aug 2002
Posts: 118
the new code is thanks to brainsucker. thanks anyway.
dselkirk is offline   Reply With Quote
Old 21st January 2005, 09:20   #11
mrtech
Junior Member
 
Join Date: Oct 2002
Posts: 46
I had the same question with regard to 9x support, basically from microsoft site stringfromguid2 does seem to be supported but it's WideCharToMultiByte that might not be fully supported with Windows 95 unless you have the Microsoft Layer for Unicode software installed. Just thought I would post this in case someone else looks this up.

My question is, how safe is it to switch and not block out users that might not have this installed?

StringFromGUID2:
http://msdn.microsoft.com/library/de...f_m2z_2jzm.asp

WideCharToMultiByte:
http://msdn.microsoft.com/library/de...icode_2bj9.asp
mrtech is offline   Reply With Quote
Old 21st January 2005, 10:41   #12
kichik
M.I.A.
[NSIS Dev, Mod]
 
kichik's Avatar
 
Join Date: Oct 2001
Location: Israel
Posts: 11,343
It's not fully supported, but the support it does give is sufficient. The translated text is plain US-ASCII, only English letters and numbers. There shouldn't be any problem using unicows.dll, but there is no reason to.

NSIS FAQ | NSIS Home Page | Donate $
"I hear and I forget. I see and I remember. I do and I understand." -- Confucius
kichik is offline   Reply With Quote
Reply
Go Back   Winamp & Shoutcast Forums > Developer Center > NSIS Discussion

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump