Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

registry snippet

Status
Not open for further replies.

brews

Technical User
Dec 12, 2007
194
US
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
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
VS 2008 does not accept lpData as Any. It was changed to as Object.

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
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 link should give you what you need.




I used to rock and roll every night and party every day. Then it was every other day. Now I'm lucky if I can find 30 minutes a week in which to get funky. - Homer Simpson

Arrrr, mateys! Ye needs ta be preparin' yerselves fer Talk Like a Pirate Day!
 
Thanks. I'll give it a try and let you know.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top