Click to See Complete Forum and Search --> : problem with reading registry value in VB


August 24th, 1999, 11:45 AM
i kept getting memory error ('mem could not be read') when i used the following to query a registry value:

----
r1 = RegOpenKeyEx( HKEY_CURRENT_USER, "RemoteAccess", 0, KEY_QUERY_VALUE, phkResult)
if r1= ERROR_SUCCESS then
l= 50
subkey = "myteststringval"
r2 = RegQueryValueEx( phkResult, subkey$, 0, REG_EXPAND_SZ, data, l )
'I got the above mem error when stepping over this statement and couldn't proceed
...
...
RegCloseKey(phkResult)
----

all consts and declares has been made.
can anyone give me a hint why the memory error always come up ? each time
i succeeded in opening the key but failed on the query...

thanks in advance to any help, will appreciate it.

Ying

Miguel
August 26th, 1999, 07:40 AM
Hi Ying:
I read the windows registry with the next code and work fine... Perhaps you can try it.
Good luck, Bye


lResult = RegOpenKeyEx(HKEY_LOCAL_MACHINE, Clave, 0, KEY_READ, hKey)

If lResult = ERROR_SUCCESS then

Dim lType as Long
Dim lReturned as Long


lResult = RegQueryValueEx(hKey, "MyString", 0, lType, 0, lReturned)


Call RegCloseKey(hKey)

Ravi Kiran
August 27th, 1999, 01:51 AM
Remove the $, and try!!, because the way VB interprets some of the 'old' basic syntax could be confusing!!.
...
subkey = "myteststringval"
' subkey$ = "myteststringval" ' have like this,if you want!!
' No $ in next line!
r2 = RegQueryValueEx( phkResult, subkey, 0, REG_EXPAND_SZ, data, l )