|
-
May 3rd, 1999, 02:04 PM
#1
using RegQueryValueEx
I would like to know how to read the information from a key using RegQueryValueEx??
-
May 3rd, 1999, 02:25 PM
#2
Re: using RegQueryValueEx
First, if you can, use one of the Registry wrapper classes you can find at this web site. Only a masochist would try to use the Registry without one (I know, I did it).
If you can't do that, here's a snippet from my own wrapper class:
// Read a string from the Registry. Returns true to mean the string was there.
bool MyRegistry::ReadValueString(const CString& sValueName, CString& sValue) const
{
VALIDATE;
_ASSERTE(m_hRootKey && "m_hRootKey is NULL");
_ASSERTE(m_hSubKey && "m_hSubKey is NULL");
_ASSERTE(! m_sSubKey.IsEmpty() && "m_sSubKey is empty");
bool bReturn(false);
LONG lnReturn(ERROR_SUCCESS);
DWORD dwType(0L);
DWORD dwDataSize(0);
// First we have to get the size of the string so we know how
// much space to allocate.
bReturn = (ERROR_SUCCESS == (lnReturn = ::RegQueryValueEx(
m_hSubKey, // Handle of key to query
sValueName, // Name of value to query
NULL, // Reserved
&dwType, // Type
NULL, // Data buffer
&dwDataSize))); // Size of value data
if (bReturn) {
BYTE* pData = reinterpret_cast<BYTE*> (sValue.GetBuffer(dwDataSize + 1));
// Now actually get the string.
bReturn = (ERROR_SUCCESS == (lnReturn = ::RegQueryValueEx(
m_hSubKey, // Handle of key to query
sValueName, // Name of value to query
NULL, // Reserved
&dwType, // Type
pData, // Data buffer
&dwDataSize))); // Size of value data
sValue.ReleaseBuffer();
}
return bReturn;
}
LA Leonard - http://www.DefinitiveSolutions.com
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|