Sistema: Windows 7 32bit
Lingua: C++Perché la funzione RegQueryValueEx() restituisce ERROR_FILE_NOT_FOUND durante il tentativo di leggere da una chiave del Registro di sistema?
ho cercato di accedere al registro HKEY_LOCAL_MACHINE\\HARDWARE\\DEVICEMAP\\Scsi\\Scsi Port 0
, chiave Driver
(tipo REG_SZ
) - nessun problema.
Lo stesso per la lettura da HKEY_LOCAL_MACHINE\\HARDWARE\\DEVICEMAP\\SERIALCOMM
, tutte le chiavi (tipo REG_SZ
) hanno barre, ad esempio \Device\Serial0
.
Durante la lettura di tali chiavi ritorna sempre 2 (senza tale file) con il seguente codice di esempio:
HKEY hKey = 0;
DWORD dwType = REG_SZ;
char buf[255] = {0};
DWORD dwBufSize = sizeof(buf);
if(RegOpenKeyEx(HKEY_LOCAL_MACHINE, TEXT("HARDWARE\\DEVICEMAP\\SERIALCOMM"), 0, KEY_QUERY_VALUE, &hKey) == ERROR_SUCCESS)
{
auto ret = RegQueryValueEx(hKey, TEXT("\Device\Serial0"), 0, &dwType, (LPBYTE)buf, &dwBufSize);
// ret always == 2 for key with slashes
--- CUT ---
Qual è il modo corretto di leggere i valori chiave con tagli in nome?
Sopra è stato correttamente risposto da Cody Gray.
Sotto un altro numero.
Im ottenendo lo stesso problema quando Im usando variabile anziché una stringa di testo.
Iv considerato sia avvicina con barre singole e doppie:
HKEY hKey = 0;
DWORD keyType = REG_SZ;
TCHAR buf[255] = {0};
DWORD bufSize = sizeof(buf);
QSettings winReg("HKEY_LOCAL_MACHINE\\HARDWARE\\DEVICEMAP\\SERIALCOMM", QSettings::NativeFormat);
auto comsKey = winReg.allKeys();
FOREACH(auto com, comsKey)
{
// FOREACH - boost macro
// comsKey = QList<QString> (list of key names) [from Qt framework]
// com = QString (single key name) [from Qt framework]
if(RegOpenKeyEx(HKEY_LOCAL_MACHINE, TEXT("HARDWARE\\DEVICEMAP\\SERIALCOMM"), 0, KEY_QUERY_VALUE, &hKey) == ERROR_SUCCESS)
{
wchar_t* keyw = new wchar_t();
//com.replace("/", "\\\\"); <- checked both variants commented and not commented; com == /Device/Serial0 so im converting to \\Device\\Serial0
int size = com.size();
mbstowcs(keyw, com.toStdString().data(), size);
//auto ret = RegQueryValueEx(hKey, TEXT("\\Device\\Serial0"), 0, &keyType, (LPBYTE)buf, &bufSize); // <- this works!
auto ret = RegQueryValueExW(hKey, (LPCWSTR)&keyw, 0, &keyType, (LPBYTE)buf, &bufSize); // <- this one not works!
ho provato tutte le varianti con "\ Device ..", "/ Dispositivo", "\ Device", ecc
testo ("\\ dispositivo \\ Serial0")? –
@Werner, no, la funzione 'RegQueryValueEx' * solo * richiede il valore di una chiave di registro. I valori sono le coppie nome/dati memorizzate all'interno delle chiavi. Quindi non puoi passare un percorso nidificato di chiavi come descrivi perché i valori non hanno percorsi. Certo, la terminologia è abbastanza confusa, Raymond Chen ha tentato di spiegarlo [qui] (http://blogs.msdn.com/b/oldnewthing/archive/2009/02/04/9394113.aspx). –