User Tools

Site Tools


creating_20a_20globally_20unique_20identifier

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

creating_20a_20globally_20unique_20identifier [2018/03/31 13:19]
127.0.0.1 external edit
creating_20a_20globally_20unique_20identifier [2018/04/17 15:23] (current)
tbest3112 Added syntax highlighting
Line 4: Line 4:
   {A8A8D3E5-713D-4C00-897E-F3B225E3A3AF}   {A8A8D3E5-713D-4C00-897E-F3B225E3A3AF}
 GUIDs are used for a number of purposes in Windows, most notably to identify a **COM interface** (IID) or **class** (CLSID); in those cases you must discover the correct value to use from Microsoft'​s documentation.\\ \\  GUIDs are also useful whenever you need to identify something uniquely. For example in the article [[/​Detecting%20a%20second%20instance%20of%20a%20program|Detecting a second instance of a program]] it is suggested that a GUID be used as the **UniqueLockName**. In such cases it is up to you to create a GUID for the purpose.\\ \\  There is no guarantee that a GUID is genuinely unique, but statistically the likelihood of any two being the same is small. Whilst you could simply make up your own 128-bit number 'at random'​ (whatever that means) it is far better to use one of the means provided specially for the purpose. One is the following website, which will create a new GUID on request: http://​www.famkruithof.net/​uuid/​uuidgen.\\ \\  An alternative method is to use your own program. The code below will generate a new GUID whenever you need one:\\ \\  GUIDs are used for a number of purposes in Windows, most notably to identify a **COM interface** (IID) or **class** (CLSID); in those cases you must discover the correct value to use from Microsoft'​s documentation.\\ \\  GUIDs are also useful whenever you need to identify something uniquely. For example in the article [[/​Detecting%20a%20second%20instance%20of%20a%20program|Detecting a second instance of a program]] it is suggested that a GUID be used as the **UniqueLockName**. In such cases it is up to you to create a GUID for the purpose.\\ \\  There is no guarantee that a GUID is genuinely unique, but statistically the likelihood of any two being the same is small. Whilst you could simply make up your own 128-bit number 'at random'​ (whatever that means) it is far better to use one of the means provided specially for the purpose. One is the following website, which will create a new GUID on request: http://​www.famkruithof.net/​uuid/​uuidgen.\\ \\  An alternative method is to use your own program. The code below will generate a new GUID whenever you need one:\\ \\ 
 +<code bb4w>
         SYS "​LoadLibrary",​ "​OLE32.DLL"​ TO ole32%         SYS "​LoadLibrary",​ "​OLE32.DLL"​ TO ole32%
         SYS "​GetProcAddress",​ ole32%, "​CoCreateGuid"​ TO CoCreateGuid%         SYS "​GetProcAddress",​ ole32%, "​CoCreateGuid"​ TO CoCreateGuid%
Line 13: Line 14:
         SYS "​WideCharToMultiByte",​ 0, 0, guidw%, -1, guida%, 40, 0, 0         SYS "​WideCharToMultiByte",​ 0, 0, guidw%, -1, guida%, 40, 0, 0
         PRINT $$guida%         PRINT $$guida%
 +</​code>​
 The GUID is available as a 128-bit number in the structure **guid{}**, as a Unicode (16-bit) string at **guidw%** and as a NUL-terminated ANSI (8-bit) string at **guida%**. The GUID is available as a 128-bit number in the structure **guid{}**, as a Unicode (16-bit) string at **guidw%** and as a NUL-terminated ANSI (8-bit) string at **guida%**.
creating_20a_20globally_20unique_20identifier.txt ยท Last modified: 2018/04/17 15:23 by tbest3112