如何读取registry项值

我使用以下代码创buildregistry项:

LPCTSTR lpNDS= TEXT("SOFTWARE\\myKEY"); if(OK==ERROR_SUCCESS) { MessageBox ( NULL, "Success", _T("SimpleShlExt"), MB_ICONINFORMATION ); } else { MessageBox ( NULL, "Failed" , _T("SimpleShlExt"), MB_ICONINFORMATION ); } LONG openRes = RegCreateKeyEx( HKEY_LOCAL_MACHINE, lpNDS, 0, NULL, REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, NULL, &hRegKey, NULL); if (openRes!=ERROR_SUCCESS) MessageBox ( NULL, "Registry Createion Failed", _T("SimpleShlExt"), MB_ICONINFORMATION ); 

现在我正在写关键使用:

 CSimpleShlExt::WriteToRegistry(LPSTR lpRegKeyVal) { LONG setRes = RegSetValueEx (hRegKey, "NDS", 0, REG_SZ, (LPBYTE)lpRegKeyVal, strlen(lpRegKeyVal)+1); CloseRegistryKey(); } 

现在我正在尝试读取使用WriteToRegistry函数创build的registry项值。 我曾尝试过

 RegOpenKeyEx(hRegKey,lpNDS,0,KEY_QUERY_VALUE,&hRegKey); 

但是这是失败的。

我应该使用哪个函数来读取密钥中包含的值?

你可以尝试像这样:

 TCHAR szValue[TEMP_STR_SIZE] = {0}; DWORD dwStorageSize = TEMP_STR_SIZE; LPBYTE lpStorage = reinterpret_cast<LPBYTE>(szValue); // In case of registry value retrieval failure if (ERROR_SUCCESS != RegQueryValueEx(hRegKey, _T("NDS"), 0, 0, lpStorage, &dwStorageSize)) { // Prompt error } 

编辑:
只是注意到没有子键,改变了我的示例代码

我应该使用哪个函数来读取密钥中包含的值?

尝试RegQueryValue和/或RegEnumValue 。 阅读文档,看看哪一个最适合您的需求。