RegOpenKeyEx / RegGetValue returns ERROR_FILE_NOT_FOUND on existing keys

Registry functions are returned "not found" on keys that certainly exist. I have the correct encoding and using double backslash so that is not a problem.

Here is the key export result:

[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Netmon3] "NetmonVersion"="3.4.2350.0" "NPLVersion"="03.02" "InstallDir"="C:\\prog\\netmon3\\" "NetmonEdition"="Capture and Parser Engine" 

Here is the function call:

 x = RegOpenKeyExA( HKEY_LOCAL_MACHINE, "SOFTWARE\\Microsoft\\Netmon3", 0, KEY_READ, &hKey); 

The return value of x is 2, which means ERROR_FILE_NOT_FOUND . Using just " SOFTWARE\\Microsoft " as the line works fine.

Calling RegGetValue () has the same problem:

 x = RegGetValueA( HKEY_LOCAL_MACHINE, "SOFTWARE\\Microsoft\\Netmon3", "InstallDir", RRF_RT_ANY, NULL, (PVOID)install_directory, &BufferSize ); 

Again, I get 2 as a result, which means it is not found.

I checked the permissions for it, and all "Users" have "Read" permissions.

No matter what I am missing, I need to see something obvious, but I break my brains, I do not see this.

-

Marsh Ray has the following answer: I was building a 32-bit version on a 64-bit system, and the installation of Netmon3 was 64-bit. Changing the build settings to 64-bit fixed the problem.

+4
source share
2 answers

Perhaps you are running as a 32-bit process on 64-bit Windows?

+4
source

You can also use 32-bit code, but then you must specify an additional flag:

 REGSAM flag = KEY_QUERY_VALUE|KEY_ENUMERATE_SUB_KEYS; if(isWin64Bit()) flag |= KEY_WOW64_64KEY; else flag |= KEY_WOW64_32KEY; LONG err = ::RegOpenKeyEx(HKEY_LOCAL_MACHINE, SOME_REGKEY, 0, flag, &hKey); 

An implementation of the isWin64Bit method can be found here .

+1
source

All Articles