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();
      return class_description;
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

CString CObjDlg::ClassDescription(const CString strclsid) const
    CString class_description = _T("Not Available");
    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;

    return class_description;

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
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 ???

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

This method works fine with
RegOpenKey API ???

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.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
System Programming

From novice to tech pro — start learning today.