[RESOLVED] Registry handling... simple question...
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:
Code:
SaveSetting("Registry Example", "Form Location", "Left", 200)
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:
Code:
SaveSetting(HKEY_CURRENT_USER, "Form Location", "Left", 200)
?
My other question is... do i need to compile a vista version and an xp and previous version? or just using vista mods would work on previous??
Thx! :)
Re: Registry handling... simple question...
ermmm no one? i know its weekend but i don't think this very difficult and other threads are getting resolved :P
well ill wait... thx!
Re: Registry handling... simple question...
You can find something here ;)
I believe you don't have to compile two versions. You can check which OS version is being used with code and make two (or more) separate actions.
Re: Registry handling... simple question...
Kk but for writing them to the HKEY_CURRENT_USER is like i said??
Re: Registry handling... simple question...
Quote:
Originally Posted by VB<3er
Kk but for writing them to the HKEY_CURRENT_USER is like i said??
What?! :)
Re: Registry handling... simple question...
:P
If i want to write to the HKEY_CURRENT_USER...would i do it like this:
SaveSetting(HKEY_CURRENT_USER, "Example", "example", example.value)
??
Re: Registry handling... simple question...
VB's registry functions save to HKEY_CURRENT_USER\Software\VB and VBA Program Settings
Thus SaveSetting("Registry Example", "Form Location", "Left", 200) saves to HKEY_CURRENT_USER\Software\VB and VBA Program Settings\Registry Example
Re: Registry handling... simple question...
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!
Re: Registry handling... simple question...
1 Attachment(s)
Re: Registry handling... simple question...
Attached the registry class I wrote/assembled, which will let you read and write to anywhere in the registry.
Sample usage:
vb Code:
Dim reg As clsRegistry
Set reg = New clsRegistry
reg.WriteNumber "Software\CompanyName\ProgramName\Form Location", "Left", 200
Set reg = Nothing
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.
Re: Registry handling... simple question...
Well thx... i'll see what i do... thx!!
Re: [RESOLVED] Registry handling... simple question...
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
Thx!