Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Unique ID Generation
Message
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Miscellaneous
Thread ID:
00259668
Message ID:
00259712
Views:
14
>I don't remeber where I found the below code, but thanks to the original author. I have a coupla questions on it, though.
> 1. What is this Windows library based on (NIC, hd id, etc)?

If an Ethernet NIC is present, the primary NIC's MAC address is used as a part of the seed to make it globally unique , otherwise, there's a fairly complex mechanism, that is only guarenteed to be unique for a machine, so adding the NetBIOS name to the UUID string should be adequate to ensure uniqueness within a network environment. The MSDN entry on CreateUuid() is rather specific about the uniqueness guarentee.

> 2. How do I know these are "really" unique across time & space?
>
>*Create a Universally Unique ID
>*Adapted from the book Visual FoxPro 5
>*Enterprise Development One of the most
>*common problems faced with developers
>*is a method of creating unique keys. This
>*is where a UUID (Univerally Unique ID)
>*comes in. UUID's are a IEEE standard
>*method of generating Universally Unique
>*values. What this means is the values
>*returned are unique across time and
>*space. The code below calls the Windows API
>*and returns a UUID.
>
>
>Function getUUID
>
>*-- The UUID Create function is in this library
>DECLARE Integer UuidCreate IN C:\Windows\System\RPCRT4.DLL ;
> String @ UUID && note that mixed case is important for UuidCreate
>
>*-- Create a buffer
>lcUUID = Space(16)
>
>*-- generate the key
>=UUIDCreate(@lcUUID)
>
>*-- Convert the binaries to hex values
>lcPart1 = BinAsHex(Substr(lcUUID,1,4))
>lcPart2 = BinAsHex(Substr(lcUUID,5,4))
>lcPart3 = BinAsHex(Substr(lcUUID,8,4))
>lcPart4 = BinAsHex(Substr(lcUUID,13,4))
>
>Local lcRetVal
>lcRetVal = lcPart1 + lcPart2 + lcPart3 + lcPart4
>Return Left(lcRetVal,8) + "-" + substr(lcRetVal,9,4) + "-" + substr(lcRetVal,13,4) + "-" + ;
> substr(lcRetVal,17,4) + "-" + Right(lcRetVal,12)
>
>PROCEDURE binashex
>Parameters lcBin
>* translates a binary string into character string of hex
>LOCAL lcChars, lnBin
>
>lcChars = ""
>FOR lnDigit = 1 TO LEN(lcBin)
> lnBin = ASC(SUBSTR(lcBin, lnDigit, 1))
> lcChars = lcChars + Hex2Char(INT(lnBin/16)) + ;
> Hex2Char(MOD(lnBin,16))
>ENDFOR
>
>RETURN(lcChars)
>
>PROCEDURE hex2char
>* takes a hex digit value and returns a character from 0-9 & A-F
>LPARAMETERS lnHex
>DO CASE
> CASE BETWEEN(lnHex,0,9)
> lnAsc = 48 + lnHex
> CASE BETWEEN(lnHex,10,15)
> lnAsc = 65 + lnHex - 10
>ENDCASE
>RETURN(CHR(lnAsc))
EMail: EdR@edrauh.com
"See, the sun is going down..."
"No, the horizon is moving up!"
- Firesign Theater


NT and Win2K FAQ .. cWashington WSH/ADSI/WMI site
MS WSH site ........... WSH FAQ Site
Wrox Press .............. Win32 Scripting Journal
eSolutions Services, LLC

The Surgeon General has determined that prolonged exposure to the Windows Script Host may be addictive to laboratory mice and codemonkeys
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform