CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Guest

    problem with reading registry value in VB

    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


  2. #2
    Join Date
    Apr 1999
    Location
    Madrid (Spain)
    Posts
    46

    Re: problem with reading registry value in VB

    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)






  3. #3
    Join Date
    May 1999
    Location
    Omika, Japan
    Posts
    729

    Re: problem with reading registry value in VB

    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 )



Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured