Thread: help with registry keys

  1. #1
    Registered User
    Join Date
    Sep 2007
    Posts
    18

    help with registry keys

    I want to be able to be able to read and change the value of a key from the registry. I have a fairly good idea of how to change it, but I am having trouble reading the value. I have looked at the msdn, but it has not helped. Here is the code:

    Code:
    case WM_CREATE:
                 {
                 RegOpenKey(HKEY_LOCAL_MACHINE,"SOFTWARE//Microsoft//Windows NT//CurrentVersion//Winlogon",&hKey);
                 char str[MAX_PATH];
                 LONG strc = MAX_PATH;
                 DWORD hi;
                 hi = RegQueryValue(hKey,"Shell",str,&strc);
                 if(hi!=ERROR_SUCCESS)
                 {
                     SetWindowText(hwnd,"Error");
                     wsprintf(str,"%d",hi);
                     MessageBox(NULL,str,"Hi",0);
                 } 
                 else
                 {
                 SetWindowText(hwnd,str);
                 }
                 }
                 break;
    I have declared hKey at the beginning of the file. What am I doing wrong?

  2. #2
    Hurry Slowly vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,788
    am having trouble reading the value
    What kind of trouble?

    wsprintf(str,"%d",hi);
    Are you working ANSI or UNICODE?
    All problems in computer science can be solved by another level of indirection,
    except for the problem of too many layers of indirection.
    – David J. Wheeler

  3. #3
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Code:
    RegOpenKey(HKEY_LOCAL_MACHINE,"SOFTWARE//Microsoft//Windows NT//CurrentVersion//Winlogon",&hKey);
    I doubt the API likes that.
    That string is equal to just what it says - SOFTWARE//Microsoft//Windows NT//CurrentVersion//Winlogon.
    Generally, for paths, you must use only ONE of the character:
    SOFTWARE/Microsoft/Windows NT/CurrentVersion/Winlogon

    However, I'm not sure if the registry likes slashes at all, so you might try with the proper backslashes:
    SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\Winlogon
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  4. #4
    Registered User
    Join Date
    Sep 2007
    Posts
    18
    I'm working with ansi. When I try with // it has system error code 6. When I try with / dev-cpp gives warnings about invalid excape characters. When I try with \ or \\ it has system error code 2.

  5. #5
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Quote Originally Posted by Anubis208 View Post
    When I try with / dev-cpp gives warnings about invalid excape characters.
    No, that's not right.
    '/' is not an escape character - '\' is.

    When I try with \ or \\ it has system error code 2.
    Error #6 means invalid handle - possibly invalid path format?
    Error #2 means path can't be found, which is also weird.
    Last edited by Elysia; 05-24-2008 at 09:33 AM.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  6. #6
    Registered User
    Join Date
    Sep 2007
    Posts
    18
    Regardless of the slashes, I get either a 2 or 6, and I know that key exists, I can open it in regedit.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Writing registry keys in windows
    By samus250 in forum C Programming
    Replies: 12
    Last Post: 06-29-2008, 01:43 PM
  2. Registry Keys
    By cgod in forum Windows Programming
    Replies: 3
    Last Post: 11-12-2004, 05:12 AM
  3. Registry Keys in C++
    By Apoc in forum Windows Programming
    Replies: 1
    Last Post: 08-21-2004, 09:46 PM
  4. Recusively delete registry keys
    By SMurf in forum Windows Programming
    Replies: 4
    Last Post: 01-22-2004, 11:24 PM
  5. Interesting Registry Stuff (Keys, Values, etc.)
    By civix in forum A Brief History of Cprogramming.com
    Replies: 9
    Last Post: 01-27-2003, 09:58 AM