views:

313

answers:

1

Hi I am able to open the registry path i.e "Software\Mozilla\Mozilla Firefox" in RegOpenKeyEx.but i am trying to fetching "CurrentVersion" using RegQueryValueEx().But i am not getting the curent version.can u pls send me some code example.

+1  A: 

This works for me:

// Open the key
HKEY hKey;
if( SUCCEEDED(::RegOpenKey( HKEY_LOCAL_MACHINE, TEXT("SOFTWARE\\Mozilla\\Mozilla Firefox"), &hKey )) )
{
    // Query the required buffer size for the requested value
    DWORD cbData;
    if( SUCCEEDED(::RegQueryValueEx( hKey, TEXT("CurrentVersion"), NULL, NULL, NULL, &cbData )) )
    {
        // Now that we have the size, allocate a buffer and query the value
        TCHAR* buf = new TCHAR[cbData/sizeof(TCHAR)];

        if( SUCCEEDED(::RegQueryValueEx( hKey, TEXT("CurrentVersion"), NULL, NULL, (LPBYTE)buf, &cbData )) )
        {
            ::OutputDebugString( buf );
        }
    }
}
Timbo
The Reg functions don't return an HRESULT, so SUCCEEDED isn't the most apporpriate macro. But the LONG result they return is compatible.
selbie