![]() |
#2
mrexcel2022-11-20 17:44
|

Private Sub Command3_Click()
Dim hKey As Long
Dim ret As Long
Dim lenData As Long
Dim typeData As Long
ret = RegOpenKey(HKEY_CURRENT_USER, "Software\VB and VBA Program Settings\QQ接收者", hKey)
If ret = 0 Then MsgBox "找到!" Else MsgBox "没找到!": Exit Sub '得到0 ,说明得到
'先取数据区的长度
ret = RegQueryValueEx(hKey, "receivers", ByVal 0, typeData, ByVal vbNullString, lenData)
'准备数据区
Dim buff() As Byte
ReDim buff(lenData - 1)
'读取数据
ret = RegQueryValueEx(hKey, "receivers", ByVal 0, typeData, ByVal buff(0), lenData)
Dim val As String
'去掉末尾的空字符,VB不需要这个
ReDim Preserve buff(lenData - 2)
'转化为VB中的字符串
val = StrConv(buff, vbUnicode)
MsgBox val
RegCloseKey (hKey)
End Sub
Dim hKey As Long
Dim ret As Long
Dim lenData As Long
Dim typeData As Long
ret = RegOpenKey(HKEY_CURRENT_USER, "Software\VB and VBA Program Settings\QQ接收者", hKey)
If ret = 0 Then MsgBox "找到!" Else MsgBox "没找到!": Exit Sub '得到0 ,说明得到
'先取数据区的长度
ret = RegQueryValueEx(hKey, "receivers", ByVal 0, typeData, ByVal vbNullString, lenData)
'准备数据区
Dim buff() As Byte
ReDim buff(lenData - 1)
'读取数据
ret = RegQueryValueEx(hKey, "receivers", ByVal 0, typeData, ByVal buff(0), lenData)
Dim val As String
'去掉末尾的空字符,VB不需要这个
ReDim Preserve buff(lenData - 2)
'转化为VB中的字符串
val = StrConv(buff, vbUnicode)
MsgBox val
RegCloseKey (hKey)
End Sub