Click to See Complete Forum and Search --> : Read Registry Code


DivZr0
February 14th, 2005, 11:16 AM
Hey guys, I'm fairly a newbie to C++ and I'm also out of my leauge here, I read a little in the forums about how to read registry keys, apparently I just can't get it. I'm just trying to read a simple key with a console application.



#include "StdAfx.h"

#include <windows.h>

#include <iostream.h>

#include <iomanip.h>

#include <string.h>

#include <stdlib.h>



void main ()
{


HKEY hKey;

DWORD dwType;

DWORD dwSize;



RegOpenKeyEx(HKEY_LOCAL_MACHINE, "Software",0 , KEY_READ, &hKey);

RegOpenKeyEx(hKey, "Dev-C++", 0, KEY_READ, &hKey);


cout << RegQueryValueEx(hKey, "Install_Dir", NULL, &dwType, NULL, &dwSize) <<endl;

}



Thanks muchly for your help

Andreas Masur
February 14th, 2005, 11:46 AM
Besides that there are some errors in your code...

'iostream.h' should be 'iostream'
'void main' should be 'int main'
no need for 'stdafx.h'
...

take a look at the following FAQs:

How can I access the registry? (http://www.codeguru.com/forum/showthread.php?s=&threadid=247024)
How can I read data from the registry? (http://www.codeguru.com/forum/showthread.php?s=&threadid=247020)
How can I write data to the registry? (http://www.codeguru.com/forum/showthread.php?s=&threadid=247022)

DivZr0
February 15th, 2005, 01:33 PM
I figured out everything. Thanks Andreas, but I have a follow up question...

I have functions that get the values....How do I make it cycle through all values in that particular key?

IE, a key named consoles with strings of IP addresses in them. How would I make it get the value of every one in that key?

thanks

Andreas Masur
February 15th, 2005, 01:34 PM
'RegEnumValue()' (http://msdn.microsoft.com/library/default.asp?url=/library/en-us/sysinfo/base/regenumvalue.asp)...