Following the following MSDN guide I'm trying to read a sample registry entry myself.
I was adding my own registry under HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion
My registry looks like this:
As you can see, I added a new value Test
which I'm trying to read with the following C code:
#include <stdio.h>
#include <Windows.h>
int rd() {
DWORD dataSize = {0};
LONG result = RegGetValue(
HKEY_LOCAL_MACHINE,
L"SOFTWARE\\Microsoft\\Windows\\CurrentVersion",
L"Test", // Value
RRF_RT_REG_SZ, // Flags, REG_SZ
0, // Type, non specified
0, // Data, empty for now
&dataSize); // Getting the size only
printf(":length of that registry: %d\n", dataSize);
return result;
}
int main(void) {
int ans = rd();
printf("exit code: %d \n", ans);
return 0;
}
The error code is 2
which means ERROR_FILE_NOT_FOUND
. However if I'm trying ti change the value from test
to CommonFilesDir
for example: the error code is 0 which means success.
After writing down the registry I restarted my machine.
How is it that I can find some registry values and some not where both seem to exist in the Windows Registry Editor?