使用http://msdn.microsoft.com/en-us/library/windows/desktop/ms724256(v=vs.85).aspx上的示例中的RegQueryInfoKey,不会给我注册表文件夹名称输出参数 achClass。我总是收到一个空字符串。我的问题是:我是否必须在获取键名文本之后调用任何其他函数?或者我可以使用这个,但我错过了什么?
旁注:机器是 Windows 7,64 位。
提前致谢
更新:代码
//调用站点:
HKEY hKey;
LSTATUS status= RegOpenKeyEx(HKEY_CURRENT_USER, InstanceFullName, 0, KEY_ALL_ACCESS, &hKey);
if ( status != ERROR_SUCCESS)
{
LPVOID lpMsgBuf;
FormatMessage(
FORMAT_MESSAGE_ALLOCATE_BUFFER |
FORMAT_MESSAGE_FROM_SYSTEM |
FORMAT_MESSAGE_IGNORE_INSERTS,
NULL,
status,
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), // Default language
(LPTSTR) &lpMsgBuf,
0,
NULL
);
this->MessageBox( (LPCTSTR)lpMsgBuf, GetProgramTitle(), MB_OK | MB_ICONERROR );
LocalFree( lpMsgBuf );
return;
}
status= MyRegSaveKey(hKey, sTempRegFilePath, NULL);
//调用函数
LSTATUS MyRegSaveKey(_In_ HKEY hKey, _In_ LPCTSTR lpFile, _In_opt_ LPSECURITY_ATTRIBUTES lpSecurityAttributes)
{
CXmlWriter xmlWriter;
if(!xmlWriter.Begin(lpFile))
return ERROR_CANNOT_MAKE;
LSTATUS retCode= _MyRegSaveKey(hKey, lpFile, lpSecurityAttributes, xmlWriter);
xmlWriter.Finish();
return retCode;
}
//内部调用函数
LSTATUS _MyRegSaveKey(_In_ HKEY hKey, _In_ LPCTSTR lpFile, _In_opt_ LPSECURITY_ATTRIBUTES lpSecurityAttributes, CXmlWriter& writer)
{
//http://msdn.microsoft.com/en-us/library/windows/desktop/ms724256(v=vs.85).aspx
TCHAR achKey[MAX_KEY_LENGTH]; // buffer for subkey name
DWORD cbName; // size of name string
TCHAR achClass[MAX_PATH] = TEXT(""); // buffer for class name
achClass[0] = '\0';
DWORD cchClassName = MAX_PATH; // size of class string
DWORD cSubKeys=0; // number of subkeys
DWORD cbMaxSubKey; // longest subkey size
DWORD cchMaxClass; // longest class string
DWORD cValues; // number of values for key
DWORD cchMaxValue; // longest value name
DWORD cbMaxValueData; // longest value data
DWORD cbSecurityDescriptor; // size of security descriptor
FILETIME ftLastWriteTime; // last write time
DWORD i, retCode;
TCHAR achValue[MAX_VALUE_NAME];
DWORD cchValue = MAX_VALUE_NAME;
DWORD type;
BYTE* pData= NULL;
DWORD size;
// Get the class name and the value count.
retCode = RegQueryInfoKey(
hKey, // key handle
achClass, // buffer for class name
&cchClassName, // size of class string
NULL, // reserved
&cSubKeys, // number of subkeys
&cbMaxSubKey, // longest subkey size
&cchMaxClass, // longest class string
&cValues, // number of values for this key
&cchMaxValue, // longest value name
&cbMaxValueData, // longest value data
&cbSecurityDescriptor, // security descriptor
&ftLastWriteTime // last write time
);
if(retCode != ERROR_SUCCESS)
return retCode;
//... the rest does not make any difference
return ERROR_SUCCESS;
}