CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4
  1. #1
    Join Date
    Feb 2006
    Posts
    12

    Working with registry functions

    Hi all,

    I'm experimenting with the registry functions, i can create en new key but can't seem to add data to a key, what am im doing wrong ?


    Code:
    	HKEY hKey;
    	DWORD dwSize=MAX_PATH;
      	struct resbuf *args = NULL; 
    	char *Path;
    	char *Key;
    	char *Value;
    	DWORD dwType=0;
    	char str[256];
    
    
           DWORD dwDisp = 0;
           LPDWORD lpdwDisp = &dwDisp;
    
    if (RegCreateKeyEx (HKEY_CURRENT_USER, Path, 0, NULL,0,0,NULL, &hKey, lpdwDisp) == ERROR_SUCCESS)
        { 
    
    /// till here it works 
    		if (RegSetValueEx(hKey, Key, 0, REG_SZ, Value, sizeof(Value))== ERROR_SUCCESS)
    		{
         		fdt_rett();
    		}
    		else
    		{
    			fdt_retnil();
            }
    	}
    	else
    	{
    		fdt_retnil();
        }

  2. #2
    Join Date
    Nov 2005
    Location
    India, Kerala, Trivandrum
    Posts
    37

    Re: Working with registry functions

    RegCreateKeyEx (HKEY_CURRENT_USER, Path, 0, NULL,0,0,NULL, &hKey, lpdwDisp)
    Modify the above to this...

    RegCreateKeyEx (HKEY_CURRENT_USER, Path, 0, NULL, 0, KEY_SET_VALUE, NULL, &hKey, lpdwDisp)

    Take a look in MSDN for further details...

  3. #3
    Join Date
    Feb 2006
    Posts
    12

    Thumbs up Re: Working with registry functions

    Great ! it works thank you !!!!

  4. #4
    Join Date
    May 2005
    Posts
    4,954

    Re: Working with registry functions

    You have another bug in your code in this line:
    Code:
        if (RegSetValueEx(hKey, Key, 0, REG_SZ, Value,sizeof(Value))== ERROR_SUCCESS)
    Value is declared as a pointer hence the sizeof will return 4 bytes so you wont be able to write string longer than that.
    look in the FAQ for more info: How can I write data to the registry?.

    Cheers
    If a post helped you dont forget to "Rate This Post"

    My Article: Capturing Windows Regardless of Their Z-Order

    Cheers

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured