has
asked on
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_CLASS ES_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;
}
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(
{
CString class_description = "Not Available";
HKEY hkCLSID;
if(RegOpenKeyEx(HKEY_CLASS
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;
}
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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.
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.
ASKER
RegOpenKeyEx(HKEY_CLASSES_
RegQueryValueEx(hkCLSID, NULL, NULL, NULL, lpszDesc, &dwSize);
would work but not the following
two step method wont work ???
RegOpenKeyEx(HKEY_CLASSES_
RegQueryValueEx(hkCLSID, NULL, NULL, _T("{0000......}"), lpszDesc, &dwSize);
This method works fine with
RegOpenKey API ???