Cant read registry entry in MFC using

I am using the following function
     RegOpenKeyEx(HKEY_LOCAL_MACHINE, "SYSTEM\\CurrentSet\\WebServices\\Netlogon", 0,KEY_READ, &hKey) == ERROR_SUCCESS)
to open the key.
This function returns SUCCESS indicating that it has opened the key. However when I try to read one of the values under this key by using the following function

DWORD DataType ; DWORD DataSize;DWORD lpData;
::RegQueryValueExW(hKey, KEYNAME, NULL, &DataType, ( LPBYTE )&lpData, &DataSize);              

it does nothing the value in lpData remains zero where as the value should be 2.

Any ideas to what might be going wrong.
Who is Participating?
PriyeshConnect With a Mentor Commented:
Initialize the DataSize variable before you make your call.
if you are querying for a REG_DWORD type, set the DataSize = sizeof(DWORD).

if you want to know the size of data that is to be read, pass the lpData as NULL and look at the value filled in DataSize after the function call.

All Courses

From novice to tech pro — start learning today.