-
i am using the following code to read registry values, it works fine with the exception that if i read to many values one after the other i get a protection fault in OLEAUT32.DLL, i've tried figureing out the problem but i havent been able to, im hoping a pair of fresh eyes will be able to spot the problem.
'---declarations
Public Declare Function RegCloseKey Lib "advapi32.dll" (ByVal hKey As Long) As Long
Public Declare Function RegOpenKeyEx Lib "advapi32.dll" Alias "RegOpenKeyExA" (ByVal hKey As Long, ByVal lpSubKey As String, ByVal ulOptions As Long, ByVal samDesired As Long, phkResult As Long) As Long
Public Declare Function RegQueryValueExNull Lib "advapi32.dll" Alias "RegQueryValueExA" (ByVal hKey As Long, ByVal lpValueName As String, ByVal lpReserved As Long, lpType As Long, lpData As Long, lpcbData As Long) As Long
Public Declare Function RegQueryValueExLong Lib "advapi32.dll" Alias "RegQueryValueExA" (ByVal hKey As Long, ByVal lpValueName As String, ByVal lpReserved As Long, lpType As Long, lpData As Long, lpcbData As Long) As Long
Public Declare Function RegQueryValueExString Lib "advapi32.dll" Alias "RegQueryValueExA" (ByVal hKey As Long, ByVal lpValueName As String, ByVal lpReserved As Long, lpType As Long, ByVal lpData As String, lpcbData As Long) As Long
Public Const ERROR_SUCCESS = 0&
Public Const HKEY_LOCAL_MACHINE = &H80000002
'---function to read registry vals
Public Function ReadRegValue(lRoot As Long, sSubKey As String, sValueName As String) As String
lResult = RegOpenKeyEx(lRoot, sSubKey, 0, KEY_QUERY_VALUE, hKeyHandle)
If lResult <> ERROR_SUCCESS Then
lResult = RegCloseKey(hKeyHandle)
Exit Function
End If
Lrc = RegQueryValueExNull(hKeyHandle, sValueName, 0&, lType, 0&, Lcch)
Select Case lType
Case REG_SZ
sValue = String(Lcch, 0)
Lrc = RegQueryValueExString(hKeyHandle, sValueName, 0&, lType, sValue, Lcch)
ReadRegValue = Left(sValue, Lcch - 1)
Case REG_DWORD
Lrc = RegQueryValueExLong(hKeyHandle, sValueName, 0&, lType, lValue, Lcch)
If Lrc = ERROR_SUCCESS Then ReadRegValue = Str(lValue)
Case Else
Lrc = -1
End Select
lResult = RegCloseKey(hKeyHandle)
End Function
'---end code
'example:
lResult = ReadRegValue(HKEY_LOCAL_MACHINE,"Software\Microsoft\Windows\CurrentVersion, "ProductName")
lResult = ReadRegValue(HKEY_LOCAL_MACHINE,"Software\Microsoft\Windows\CurrentVersion, "ProductKey")
'--end example
it can read 1 value from the regsitry and sometimes 2, any more than that and it throws a protection fault, i dont understand why.
thank you for any help on this, i appreciate it.
-
Sorry i cant help ya there, but the way i do it is
Savesetting(Appname,Section,Key,Value)
No errors this way.
I think that would work, no?
-sorry this probably isn't much help.
...oh yeah, does anybody know how to write to the startup registry?