Have a snippet written by Dev Ashish and Terry Kreft to read the registry. Am trying to convert a VB6 program to vs2008 but am having trouble with the code.
this part
VS 2008 does not accept lpData as Any. It was changed to as Object.
When the snippet is first read
vb6 returns a 0 for lngTmp and a number for KEY_READ and therefore lngTmp = ERROR_Success and completes
by returning "No Key" or varRet which is used later.
whereas vs 2008 returns 87 for lngTmp and true for KEY_READ.But VS2008 returns a positive number for lngTmp and True for Key_Read.
The msgbox returns vbObjecterror -2147221504 in VS2008.
Any ideas on how to convert would be helpfull.
this part
Code:
Private Declare Function apiRegQueryValueEx Lib "advapi32.dll" _
Alias "RegQueryValueExA" (ByVal hKey As Long, _
ByVal lpValueName As String, ByVal lpReserved As Long, _
ByRef lpType As Long, lpData As Any, _
ByRef lpcbData As Long) As Long
When the snippet is first read
Code:
Function fReturnRegKeyValue(ByVal lngKeyToGet As Integer, ByVal strKeyName As String, ByVal strValueName As String) As String
Dim lnghKey As Integer
Dim strClassName As String
Dim lngClassLen As Integer
Dim lngReserved As Integer
Dim lngData As Integer
Dim lngTmp As Integer
Dim strRet As String
Dim varRet As String
Dim lngRet As Integer
On Error GoTo fReturnRegKeyValue_Err
'Open the key first
lngTmp = apiRegOpenKeyEx(lngKeyToGet, strKeyName, 0, KEY_READ, lnghKey)
'Are we ok?
If Not (lngTmp = ERROR_SUCCESS) Then Err.Raise(lngTmp + vbObjectError)
vb6 returns a 0 for lngTmp and a number for KEY_READ and therefore lngTmp = ERROR_Success and completes
Code:
fReturnRegKeyValue_Exit:
fReturnRegKeyValue = varRet
lngTmp = apiRegCloseKey(lnghKey)
Exit Function
fReturnRegKeyValue_Err:
varRet = "No Key"
MsgBox(Err.Number & " - " & Err.Description)
Resume fReturnRegKeyValue_Exit
End Function
whereas vs 2008 returns 87 for lngTmp and true for KEY_READ.But VS2008 returns a positive number for lngTmp and True for Key_Read.
The msgbox returns vbObjecterror -2147221504 in VS2008.
Any ideas on how to convert would be helpfull.