• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 351
  • Last Modified:

RegQueryValueEx

I have the following code that works fine. But I want to (as suggested in MSDN) use RegQueryValueEx instead of
RegQueryValue. I return the Class description given in the registry for a particular CLSID. I take the CLSID as CString and return the desciption.
Here it is:

CString CObjDlg::ClassDescription(const CString strclsid) const
{
      CString class_description = "Not Available";
      HKEY hkCLSID;
      
      if(RegOpenKeyEx(HKEY_CLASSES_ROOT, _T("CLSID"), 0,
                              KEY_READ, &hkCLSID) == ERROR_SUCCESS)
      {
            long Size = 0;
            RegQueryValue(hkCLSID, strclsid, NULL, &Size);
            std::vector<TCHAR> desc(Size + 1);
            Size = desc.size();
            if(RegQueryValue(hkCLSID, strclsid, desc.begin(), &Size)
                  == ERROR_SUCCESS) class_description = desc.begin();
            RegCloseKey(hkCLSID);
      }
      return class_description;
}
0
has
Asked:
has
  • 2
1 Solution
 
chensuCommented:
CString CObjDlg::ClassDescription(const CString strclsid) const
{
    CString class_description = _T("Not Available");
 
    HKEY hkCLSID;
    CString strSubkey = _T("CLSID\\") + strclsid;

    if (::RegOpenKeyEx(HKEY_CLASSES_ROOT, strSubkey, 0, KEY_READ, &hkCLSID) == ERROR_SUCCESS)
    {
        DWORD dwSize = 0;
 
        if (::RegQueryValueEx(hkCLSID, NULL, NULL, NULL, NULL, &dwSize) == ERROR_SUCCESS)
        {
            LPTSTR lpszDesc = new TCHAR[dwSize];
 
            if (::RegQueryValue(hkCLSID, NULL, NULL, NULL, lpszDesc, &dwSize) == ERROR_SUCCESS)
                class_description = lpszDesc;

            delete []lpszDesc;
        }
 
        ::RegCloseKey(hkCLSID);
    }

    return class_description;
}
0
 
hasAuthor Commented:
If you could tell me why

RegOpenKeyEx(HKEY_CLASSES_ROOT, _T("CLSID\\{0000......}"), 0, KEY_READ, &hkCLSID);
RegQueryValueEx(hkCLSID, NULL, NULL, NULL, lpszDesc, &dwSize);

would work but not the following
two step method wont work ???

RegOpenKeyEx(HKEY_CLASSES_ROOT, _T("CLSID"), 0, KEY_READ, &hkCLSID);
RegQueryValueEx(hkCLSID, NULL, NULL, _T("{0000......}"), lpszDesc, &dwSize);

This method works fine with
RegOpenKey API ???


0
 
chensuCommented:
The 4th parameter of RegQueryValueEx is the address of buffer for value type. You might have wanted to use

RegQueryValueEx(hkCLSID, _T("{0000......}"), NULL, NULL, lpszDesc, &dwSize);

But this won't work because {0000......} is a subkey of the CLSID key instead of its value name and the 2nd parameter of RegQueryValueEx is supposed to be a value name.

If you don't understand, open the Registry Editor, the items in the left pane are called keys and subkeys while the items in the right pane are called values and a value has its name, data and type.
0

Featured Post

[Webinar] Improve your customer journey

A positive customer journey is important in attracting and retaining business. To improve this experience, you can use Google Maps APIs to increase checkout conversions, boost user engagement, and optimize order fulfillment. Learn how in this webinar presented by Dito.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now