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

    WINDOWS REGISTRY ???

    HI,

    In GetProfilestring(...) API, the first two parametrers are section name and key name can some body explain me about these two params??

    Thanx


  2. #2
    Join Date
    Apr 1999
    Location
    VA BEACH
    Posts
    467

    Re: WINDOWS REGISTRY ???

    GetProfleString Will retrive from ini files unless specified. I am not sure how yuo specify with the api, but if you use the CWinApp::GetProfileString/WriteProfileString it will retrieve values from teh registry. You must call the SetRegistryKey() function to set the registry key under the default location which is
    HKEY_CURRENT_USER\Software in the registry.
    To use a subkey under that you can use m_pszProfileName member.
    CString GetProfileString( LPCTSTR lpszSection, LPCTSTR lpszEntry, LPCTSTR lpszDefault = NULL ); is the function header.
    the lpszSection is the name of the section
    ex: if we have a key called HKEY_CURRENT_USER\Software\Liberty Tax Service\stuff, stuff is the subkey.
    the next param is lpszEntry whcih is the name of the value you wish to retrieve.
    and then the last param is a default return string. ask if you still have questons


    Jim Hewitt, Liberty Tax Service

  3. #3
    Guest

    Re: WINDOWS REGISTRY ???

    Hi,

    Thanx for the answer.

    I have a query.I am looking to get the path of realplay.exe which is in

    HKEY_CLASSES_ROOT\\Software\\RealNetworks\\RealPlayer\\6.0\\Preferences

    How do I use CWinApp::GetProfileString(...)??


  4. #4
    Join Date
    Apr 1999
    Location
    VA BEACH
    Posts
    467

    Re: WINDOWS REGISTRY ???

    Put this function in your InitInstance of you app
    SetRegistryKey((_T(HKEY_CLASSES_ROOT\\Software\\RealNetworks\\RealPlayer\\6.0\\Preferences”));
    then any calls you maek to get or write profile string should read from that protion of the registry.

    Jim Hewitt, Liberty Tax Service

  5. #5
    Guest

    Re: WINDOWS REGISTRY ???

    HI,
    HKEY_CLASSES_ROOT\\Software\\RealNetworks\\RealPlayer\\6.0\\Preferences\\MainApp contains the data what I am trying to retrive.

    I have SetRegKey("HKEY_CLASSES_ROOT\\Software\\RealNetworks\\RealPlayer\\6.0\\Preferences\\MainApp"); in the InitInstance of my application.

    and I am trying to retrive by using,

    GetProfileString("HKEY_CLASSES_ROOT\\Software\\RealNetworks\\RealPlayer\\6.0\\Preferences\\MainApp", "MainApp",NULL);

    Is this correct? I am unable to get the data??


  6. #6
    Join Date
    Aug 1999
    Posts
    8

    Re: WINDOWS REGISTRY ???

    I don't know what leads into this kind of discussion. Actually SetRegistryKey Always sets the key Under HKEY_CURRENT_USERS\Software . So when you say SetRegistryKey( "XXXX\\YYYY") it created entry as HKEY_CURRENT_USERS\Software\XXXX\YYYY. So you wont get any value. USe the Following code to get the Value

    HRESULT UtilityFunctions::GetRegistryKeyStrVal( HKEY hKey , LPTSTR wSubkey , LPTSTR wValname,
    TCHAR* lpszValue)
    {

    HKEY subKey;

    //Open the Registry Key
    if(::RegOpenKeyEx(hKey, wSubkey, 0, KEY_QUERY_VALUE,
    &subKey) != ERROR_SUCCESS)
    {
    lpszValue = NULL;
    return E_FAIL;
    }

    DWORD type = REG_DWORD;
    DWORD cbData = 0;

    // Get the Length of the Reg. key Value For allocation
    if(::RegQueryValueEx(subKey, wValname, NULL,
    &type, NULL, &cbData) != ERROR_SUCCESS)
    {
    lpszValue = NULL;
    return E_FAIL;
    }
    //Query for Registry Value
    type = REG_SZ;
    TCHAR *pBuf = new TCHAR[cbData + 1];
    if(::RegQueryValueEx(subKey, wValname, NULL, &type,
    (LPBYTE)pBuf, &cbData) != ERROR_SUCCESS)
    {
    lpszValue = NULL;
    return E_FAIL;
    }
    // Assign to the Return String
    _tcscpy( lpszValue , pBuf);
    //Delete the Bugger & close the Key
    delete[] pBuf;
    ::RegCloseKey(subKey);
    //return Success;
    return S_OK;
    }



  7. #7
    Guest

    Re: WINDOWS REGISTRY ???

    Thanx for the code.

    Will u tell me what exactly I need to pass as "hKey","wSubkey","wValname" . I am confused with key and subkey concept!!!.




  8. #8
    Join Date
    Aug 1999
    Posts
    8

    Re: WINDOWS REGISTRY ???

    hKey is one of the Following Value
    HKEY_LOCAL_MACHINE
    HKEY_CURRENT_USERS
    HKEY_CLASSES_ROOT etc

    i your case it is HKEY_CLASSES_ROOT

    wSubKey in your case is
    "Software\\RealNetworks\\RealPlayer\\6.0\\Preferences\\MainApp"
    wValName is NULL ( bcoz your going to retrive Default value )

    Use these value and if you have any problem contact me at [email protected]




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