CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    May 1999
    Posts
    1

    Windows Registry

    How do i load a String from the windows registry? I manage to save one, but i can't load it.


  2. #2
    Join Date
    May 1999
    Posts
    6

    Re: Windows Registry

    Easiest way is to use CWinApp::GetProfileString, provided you call CWinApp::SetProfileString. Otherwise, use RegQueryValueEx.

    "Geek used to be a four-letter word. Now it's a six-figure one."

  3. #3

    Re: Windows Registry

    How 'bout an example:

    // Write a string to the registry.
    bool MyRegistry::SaveValueString(const CString& sValueName, const CString& sValue)
    {
    VALIDATE;
    _ASSERTE(m_hRootKey && "m_hRootKey is NULL");
    _ASSERTE(m_hSubKey && "m_hSubKey is NULL");
    _ASSERTE(! m_sSubKey.IsEmpty() && "m_sSubKey is empty");

    // Build the buffer.
    bool bReturn(false);
    LONG lnReturn(ERROR_SUCCESS);
    char szData[256];
    const BYTE* pData = reinterpret_cast<const BYTE*> (szData);
    wsprintf(szData, "%s", sValue);
    _ASSERTE(lstrlen(szData) < sizeof(szData));

    // Write out the value.
    bReturn = (ERROR_SUCCESS == (lnReturn = ::RegSetValueEx(
    m_hSubKey, // Handle of key to set value for
    sValueName, // Address of value to set
    NULL, // Reserved
    REG_SZ, // Type
    pData, // Value data
    lstrlen(szData)))); // Size of value data

    // Done. Did we succeed?
    if (! bReturn) {
    DRSCRUB_LOG(REGISTRY_FAILURE, STSEV_Warning,
    "::RegSetValueEx" & lnReturn);
    }

    return bReturn;
    }

    I would seriously consider using one of the many Registry wrapper classes you can find at this site, or writing one of your own.

    LA Leonard - http://www.DefinitiveSolutions.com

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