GUID(ユニークな128ビット値)を生成          <TOP>


GUID(Global Unique Identifier)2つ以上のアイテムが同じ値を持つことがない一意な識別子(128ビット)を生成します。

CoCreateGuid GUID(ユニークな128ビット値)を生成

 

生成する度に値は変わります。

 

'================================================================
'= GUID(ユニークな128ビット値)を生成
'=    (CoCreateGuid.bas)
'================================================================
#include "Windows.bi"

' GUID(ユニークな128ビット値)を生成
Declare Function Api_CoCreateGuid& Lib "ole32" Alias "CoCreateGuid" (pGuid As Any)

Var Shared Text1 As Object
Var Shared Text2 As Object
Var Shared Button1 As Object

Text1.Attach GetDlgItem("Text1") : Text1.SetFontSize 14
Text2.Attach GetDlgItem("Text2") : Text2.SetFontSize 14
Button1.Attach GetDlgItem("Button1") : Button1.SetFontSize 14

'================================================================
'=
'================================================================
Declare Sub Button1_on edecl ()
Sub  Button1_on()
    Var id(15) As Byte
    Var i As Long
    Var GUID As String

    '正常な場合は0を返す
    If Api_CoCreateGuid(id(0)) = 0 Then
        For i = 0 To 15
            If id(i) < 16 Then
                GUID = GUID & "0" & Hex$(id(i))    '&HF以下の場合[0]を付加
            Else
                GUID = GUID & Hex$(id(i))
            End If
        Next i
    End If

    GUID = Left$(GUID, 8) & "-" & Mid$(GUID, 9, 4) & "-" & Mid$(GUID, 13, 4) & "-" & Mid$(GUID, 17, 4) & "-" & Right$(GUID, 12)

    Text2.SetWindowText GUID
End Sub

'================================================================
'=
'================================================================
While 1
    WaitEvent
Wend
Stop
End