CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    Mar 2001
    Posts
    20

    Retrieving a registry string

    In order to retrieve a Visual Basic string registry value, you have to first make ample space in a string with a function such as Space, String or something similar.
    What I want to know is if there’s any way I can find out how much space I need to set without having to query the registry value first to determine the string size, setting the space and then requerying in order to retrieve the data.
    As far as I can tell you can store up to 30,000 bytes in a registry string, class REG_SZ. But I most definitely don’t want to allocate nearly 30 KB of memory space for each registry string request.
    Any advice?


  2. #2
    Join Date
    Feb 2001
    Location
    Stamford CT USA
    Posts
    2,167

    Re: Retrieving a registry string

    I assume that you're importing RegQueryValue() API to get the string value. Anyway, instead of re-allocating 30K of space everytime you need to get the data, just allocate 1 var as a global variable and re-use it whenever you need to call up the API function.

    In a module or form

    option Explicit

    dim szRegValueBuffer as string * 30000

    Function GetRegValue(szSubKey as string) as string
    ' assuming that all declaration has been done before
    dim nBufSize as long
    nBufSize = 30000

    if (RegQueryValue(hKey, szSubKey, szRegValueBuffer, nBufSize) = 0) then
    ' got it
    GetRegValue = Left$(szRegValueBuffer, nBufSize)
    else
    ' error
    GetRegValue = ""
    end if
    End Function




    -Cool Bizs

    Good Luck,
    -Cool Bizs

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