C++ registry stuff

By Erlehacker ยท 5 replies
Nov 1, 2006
  1. I need to know how to create/modify registry keys with C++. I've heard of some system() commands for that but I haven't been able to get the exact syntax for it. Anybody willing to share the secret?
  2. Nodsu

    Nodsu TS Rookie Posts: 5,837   +6

    You have to use Windows API functions or maybe some wrapper classes.

    http://www.geocities.com/SiliconValley/2072/prgw32rg.htm gives you the "bare metal" approach using Windows system calls. I'm pretty sure there are some prettier interfaces in libraries like MFC or suchlike.
  3. Erlehacker

    Erlehacker TS Rookie Topic Starter

    You're talking to a newbie programmer here. But that's newbie programmer, and not newbie computer user. I'm gonna need some explanations on the stuff you mentioned. Isn't there something like system("regedit etc.")?
  4. Nodsu

    Nodsu TS Rookie Posts: 5,837   +6

    Sure, you can use system() to run programs, but that's very inefficient, and you can't really edit system registry from command line - you have to use temporary .REG files and suchlike. The result is something very, very ugly. My conscience does not allow to tell you how to do such an awful thing :)

    The page I linked to.. I guess it is not a very newbie-friendly..

    Basically, to get access to the system registry API, you have to include the winreg.h file.

    After that you use the RegOpenKeyEx() function to open a key. (Keys are the folder-like things in regedit). Since Windows API is totally retarded, you have to do this in a weird way. If you look at the sample code, you see that you have to define a HKEY variable and pass a reference to that to RegOpenKeyEx().

    After you have opened a key, you can work with values inside using RegQueryValueEx() and RegSetValueEx().

    You really have to chew through that article if you want to use the Windows API. Just keep thinking that the rest of the Windows API is even more horrible :)

    What kind of C++ environment are you using? You may be able to use some more user-friendly libraries.
  5. Erlehacker

    Erlehacker TS Rookie Topic Starter

    I'm using the Bloodshed Dev-C++ IDE I have done some manual registry editing so I'm on somewhat familiar ground that way.
  6. Nodsu

    Nodsu TS Rookie Posts: 5,837   +6

Topic Status:
Not open for further replies.

Similar Topics

Add your comment to this article

You need to be a member to leave a comment. Join thousands of tech enthusiasts and participate.
TechSpot Account You may also...