Ok i have a simple question about registry... I know how to write and retrieve but i have this question:
When i search for registries examples in google i always find this kind of examples:
But here in vbforums i saw that to make your app compatible with vista u need to do something like HKEY_CURRENT_USER maybe? i can't find it now
But i don't know if this would be how to do it:
Okey so then it is ok for both vista and xp isn't it?
Ive seen programs writing it like this :
Code:
Public Sub SaveString(hKey As Long, strPath As String, strValue As String, strdata As String)
'EXAMPLE:
'
'Call savestring(HKEY_CURRENT_USER, "Sof
' tware\VBW\Registry", "String", text1.tex
' t)
'
Dim keyhand As Long
RegCreateKey hKey, strPath, keyhand
RegSetValueEx keyhand, strValue, 0, REG_SZ, ByVal strdata, Len(strdata)
RegCloseKey keyhand
End Sub
Are there many differences between vb builtin and api?
Thx!
The optional last parameter (after the 200) is omitted, which means the call defaults to HKEY_CURRENT_USER.
Typically I'll make reg public and "Set = New" on startup, then set it back to Nothing when the program terminates. This way I can use it anywhere in my program with minimal hassle.
Just my last question... i found this around modified it a bit and it works pefect... but don't really know what it exactly does... there are some things i dun get can some one break it out?? would be so appreaciated!
Code:
Public Function GetString(hKey As Long, strPath As String, strVal As String)
Dim hKeyh As Long
Dim DataType As Long
Dim lResult As Long
Dim strBuf As String
Dim lDataBufSize As Long
Dim lValueType As Long
Dim intZeroPos As Integer
Call RegOpenKey(hKey, strPath, hKeyh)
lResult = RegQueryValueEx(hKeyh, strVal, 0&, lValueType, ByVal 0&, lDataBufSize)
If lValueType = REG_SZ Then
'Part i don't get... strBuf = String(lDataBufSize, " ")
lResult = RegQueryValueEx(hKeyh, strVal, 0&, 0&, ByVal strBuf, lDataBufSize)
If lResult = ERROR_SUCCESS Then
intZeroPos = InStr(strBuf, Chr$(0))
If intZeroPos > 0 Then
GetString = Left$(strBuf, intZeroPos - 1)
Else
GetString = strBuf
End If
End If
End If
End Function