Here is a fixed version
CODE
HKEY hKey;
DWORD dwSize = 0;
DWORD dwDataType = 0;
DWORD dwValue = 0;
DWORD dwError = 0;
TCHAR regValue[MAX_PATH] = {0};
DWORD ret = RegOpenKeyEx(HKEY_LOCAL_MACHINE,TEXT("Software\\Microsoft\\Windows NT\\CurrentVersion\\Winlogon") ,0,KEY_QUERY_VALUE,&hKey);
if(ret == ERROR_SUCCESS)
{
dwSize = sizeof(regValue);
if(::RegQueryValueEx(hKey,TEXT("DefaultUserName"), 0, NULL, (LPBYTE)regValue,&dwSize) != ERROR_SUCCESS)
{
::RegCloseKey(hKey);
}
else
{
std::wcout << "val: " << regValue << std::endl;
//what can i do here to display the value on hKey in an edit control?
::RegCloseKey(hKey);
}
}
You basically had an invalid path when opening up the registry path.
Also the return value is a string. Casting a dword to a byte pointer isn't going to cut it.
What helps most to track down these sort of problems is to check what the return value is and look it up.
For example RegOpenKeyEx() was return 2 which meant "The system cannot find the file specified".
If find out what the error messages are you can use the
net helpmsg error# at the command line.
Lastly, I don't what to tell you about the edit control. Are you using MFC? If you are then the CEdit class has a
SetWindowText() member function that can set the value for you.
Cheers