I am trying to read three REG_SZ values (strings) from the registry using C, but I am having no success. The function RegOpenKeyEx runs correctly, but after I then run RegQueryValueExW, I sometimes get error 2 (ERROR_FILE_NOT_FOUND), or sometimes error 127 (ERROR_PROC_NOT_FOUND). Any help would be greatly appreciated, as I've been working on getting this to work for a few days now and it has been very frustrating! Thank you so much for taking the time to assist me!
The following code gives me error 127:
TCHAR date[
11
];
TCHAR regSerialKey[
12
];
TCHAR strAN[
15
];
HKEY hkey;
unsigned
long
datalen =
sizeof
(
char
) *
11
;
ERROR_FILE_NOT_FOUND is a valid last_error that is mentioned by the function documentation, read it. This not found error can be the result of searching for an incorrect type. Use regedit while debugging to check out the actual state of the registry when you get into a breakpoint as a result of an error. Try to use a bigger buffer to receive the key value and use sizeof(date)/sizeof(date[0]) to fill up datalen. If your RegQueryValueEx call returns ERROR_MORE_DATA then the buffer is too small. In this case it can easily happen that GetLastError() returns something that is unrelated to your RegQueryValueEx call, for example the last_error of a previously failed function call.