Welcome to Dream.In.Code
Getting C++ Help is Easy!

Join 132,282 C++ Programmers for FREE! Get instant access to thousands of C++ experts, tutorials, code snippets, and more! There are 1,220 people online right now. Registration is fast and FREE... Join Now!




Having Problem Displaying Registry Value on a Edit Control

 
Reply to this topicStart new topic

Having Problem Displaying Registry Value on a Edit Control

AntiBNI
post 15 Feb, 2008 - 06:56 PM
Post #1


D.I.C Head

**
Joined: 21 Jul, 2006
Posts: 52


My Contributions


I have been triying to display a registry value in a EditControl and have failed miserably...

I need some words of wisdom(Help) happy.gif

Heres the code:

CODE

HKEY  hKey;
DWORD dwSize     = 0;
DWORD dwDataType = 0;
DWORD dwValue    = 0;

if(::RegOpenKeyEx(HKEY_LOCAL_MACHINE,"Software\\Microsoft\\WindowsNT\\CurrentVersion\\Winlogon\\DefaultUserName",0,KEY_QUERY_VALUE,&hKey) == ERROR_SUCCESS)
{
  dwSize = sizeof(dwValue);

  if(::RegQueryValueEx(hKey,"DefaultUserName",0,&dwDataType,reinterpret_cast<BYTE *>(&dwValue),&dwSize) != ERROR_SUCCESS)
  {
    ::RegCloseKey(hKey);
  }
  else
  {

//what can i do here to display the value on hKey in an edit control?

    ::RegCloseKey(hKey);
  }
}


Help will be appreciated.

User is offlineProfile CardPM

Go to the top of the page

skaoth
post 15 Feb, 2008 - 09:35 PM
Post #2


D.I.C Regular

Group Icon
Joined: 7 Nov, 2007
Posts: 337



Thanked 9 times

Dream Kudos: 100
My Contributions


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
User is online!Profile CardPM

Go to the top of the page

Reply to this topicStart new topic
Time is now: 11/22/08 12:52AM

Live C++ Help!

C++ Tutorials

Reference Sheets

C++ Snippets

Bye Bye Ads

Free DIC T-Shirt

T-Shirt Example

Related Sites

Monthly Drawing

Thumb Drive

Partners

Top Contributors

Top 10 Kudos This Month