There is a key in the registry:

HKEY_CURRENT_USER \ Software \ Posix \ NetStat

And the key has a value

Downloaded type REG_SZ with value done

Trying to read its meaning. Nothing comes out.

 #include <windows.h> #include <iostream> #include <string> using namespace std; int main() { char buf[1024]; HKEY hKey = HKEY_CURRENT_USER; ULONG result; DWORD sz = 1024; // open section and get hKey handler result = RegOpenKeyExA( hKey, "Software\\Posix\\NetStat", 0, REG_SZ, &hKey); if (result != ERROR_SUCCESS) { cout << "Can't open section" << endl; RegCloseKey(hKey); } // get desired value result = RegGetValueA( hKey, "Software\\Posix\\NetStat", "Downloaded", RRF_RT_ANY, NULL, (LPDWORD)buf, &sz); if (result != ERROR_SUCCESS) { cout << "Can't get value of Downloaded" << endl; RegCloseKey(hKey); } system("pause"); return 0; } 

After the first function is executed, the result is 0. That is, the first function works. After the second function is completed, the result is 2.

#define ERROR_FILE_NOT_FOUND 2L

Of course, the function in buf does not return any value .. Here is a link to the description of the function on MSDN. Only there is RegGetValue() .

https://msdn.microsoft.com/en-us/library/windows/desktop/ms724868(v=vs.85).aspx

1 answer 1

In general, you have a problem, apparently, here:

 result = RegOpenKeyExA( hKey, "Software\\Posix\\NetStat", 0, REG_SZ, &hKey); 

In particular, RegOpenKeyExA changes the value of &hKey . Moreover, using RegOpenKeyExA does not make sense at all, since it simply opens the key in the registry, and you need to read the value. And, as written in the comments above, the documentation has the flag RRF_SUBKEY_WOW6464KEY . Here is a working example:

 RegGetValueA( HKEY_CURRENT_USER, "Software\\Posix\\NetStat", "Downloaded", RRF_RT_ANY | RRF_SUBKEY_WOW6464KEY, NULL, (LPDWORD)buf, &sz ); 

It does not RegCloseKey to RegCloseKey either.

  • Your option does not work either. Returns 2L - Gregory
  • Show the code how you use the flag. Straight all the arguments to the RegGetValueA function. Especially the first - Artem Okonechnikov
  • I took and copied now your two parameters instead of RRF_RT_ANY in my code. The rest is unchanged - Gregory
  • Pay attention to the first argument, in particular on hKey. It is not for nothing that he is transferred to the first function by reference - Artyom Okonechnikov
  • I do that. Pass on the link. In the first function I get this value into it, and in the second one I insert hKey . Wrong ? - Gregory