Dim rc As Long, sError As String
Dim lngResult As Long, lngDisposition As Long
Dim udtSECURITY_ATTRIBUTES As SECURITY_ATTRIBUTES
Dim temp As String, tempLong As Long
'レジストリにキーを作成する
rc = RegCreateKeyEx(HKEY_CURRENT_USER, "Software\WinAPI\ReistryTest", 0&, vbNullString, _
REG_OPTION_NON_VOLATILE, KEY_CREATE_SUB_KEY Or KEY_SET_VALUE, _
udtSECURITY_ATTRIBUTES, lngResult, lngDisposition)
If rc = ERROR_SUCCESS Then
temp = Me.Text1.Text
a = 0
For b = 1 To Len(temp)
c = Asc(Mid(temp, b, 1))
If c > &H39 Or c < &H30 Then a = 1: Exit For
Next
Select Case a
Case 1
rc = RegSetValueEx(lngResult, "String", 0, REG_SZ, ByVal temp, Len(temp) + 1)
Case 0
tempLong = Val(temp)
rc = RegSetValueEx(lngResult, "Long", 0, REG_DWORD, tempLong, 4)
End Select
If rc <> 0 Then
'エラーコードからエラーメッセージを取得
sError = String(260, vbNullChar)
Call FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM, ByVal 0&, rc, 0, sError, Len(sError), 0)
MsgBox sError
Else
MsgBox "保存に成功しました"
End If
Else
'エラーコードからエラーメッセージを取得
sError = String(260, vbNullChar)
Call FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM, ByVal 0&, hKey, 0, sError, Len(sError), 0)
MsgBox sError
End If
|