Thread: Reading the registry.

  1. #1
    0x01
    Join Date
    Sep 2001
    Posts
    88

    Reading the registry.

    Compiler: MSVC++ | OS: Windows XP Pro.

    How would I read-in a key or entry from the registry(what function, and please show an example)?

    TIA, knave.

  2. #2
    0x01
    Join Date
    Sep 2001
    Posts
    88

    I don't understand... it should be working...

    Tried working with this, but failed to get it to work. any help is appreciated.

    Code:
    #include "stdio.h"
    #include "stdlib.h"
    #include "windows.h"
    #include "iostream.h"
    
    int main()
    {
    	HKEY hKey;	
    	char *lpValName = " anything",
    		 *lpKey = "Software\\etc\\etc\\etc\\etc\\etc\\";
    	DWORD dwData,dwSize,dwType;
    
    
    	if(RegOpenKeyEx(HKEY_CURRENT_USER,lpKey, NULL,KEY_READ,&hKey) == ERROR_SUCCESS)
    	{
    		dwSize = sizeof(DWORD);
    		dwType = REG_SZ; // REG_SZ ONLY!!!
    
    		if(RegQueryValueEx(hKey,lpValName,NULL,&dwType, (LPBYTE)&dwData ,&dwSize) == ERROR_SUCCESS)
    		{
    			printf(" Data from key: %s",dwData);
    		}
    		else printf("\n Could not read the registry key");
    
    	}
    	else printf("\n Failed to locate the registry key");
    	RegCloseKey(hKey);
    
    	return 0;
    }

  3. #3
    erstwhile
    Join Date
    Jan 2002
    Posts
    2,227
    Try RegCreateKeyEx instead of 'RegOpenKeyEx' as RegCreateKeyEx will create the key if it doesn't already exist or open the key if it does. Note that RegCreateKeyEx has different parameters.

    There are a couple of simple syntax errors in your posted code but I assume these are just typos.

    Hope that helps some. Good luck.
    CProgramming FAQ
    Caution: this person may be a carrier of the misinformation virus.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 7
    Last Post: 02-02-2009, 07:27 AM
  2. Replies: 2
    Last Post: 01-28-2008, 03:07 AM
  3. Reading registry
    By NoFearXD in forum Windows Programming
    Replies: 2
    Last Post: 04-14-2007, 03:52 PM
  4. Reading and writing to the Registry
    By Stan100 in forum Windows Programming
    Replies: 2
    Last Post: 07-29-2004, 12:11 PM
  5. Reading Registry Values
    By phantomlord in forum Windows Programming
    Replies: 2
    Last Post: 10-09-2003, 02:09 PM