Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C++ Win7 IE9
I'm running this code to change registry key. However; I want to add an if statement to it that query the key before the change is made. Let's say I want to change the key to "0", I would query the key and if it was "0" then the code would stop, If it's a "3" then it would continue. How can this be done with this working code that I have? Thank you.
 
#define BUFFER_SIZE 1024 //add this to your header		
HKEY hKey;			
DWORD dwErr = NO_ERROR;
 
dwErr = RegOpenKeyEx (HKEY_CURRENT_USER,L"Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings\\Zones\\3",NULL,KEY_SET_VALUE|KEY_QUERY_VALUE,&hKey);
if(ERROR_SUCCESS == dwErr)
{
	BYTE data[BUFFER_SIZE] = {0};
	DWORD dwType = REG_NONE;
 
	dwErr = RegQueryValueEx(hKey,L"1803",NULL,&dwType,data,&buffersize);
	if(ERROR_SUCCESS == dwErr && REG_DWORD == dwType)
	//If Key "1803" Value = 0 then
	//Stop
	//Else
	{
		*((LPDWORD)data) = 0;
		dwErr = RegSetValueExW(hKey,L"1803",0,REG_DWORD,data,sizeof(DWORD));
	}
	RegCloseKey (hKey);
}
Posted 19-Sep-11 10:04am

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

	if(ERROR_SUCCESS == dwErr && REG_DWORD == dwType && *((LPDWORD)data) != 0)
...
Why not also make data a DWORD type since you know it contains a DWORD value?
  Permalink  
Comments
Member 7766180 at 19-Sep-11 15:21pm
   
Thank you, Richard I appreciate the input. I will change data to DWORD on your recommendation. Have a nice day!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 OriginalGriff 200
1 George Jonsson 175
2 Kornfeld Eliyahu Peter 169
3 PIEBALDconsult 110
4 Richard MacCutchan 85
0 OriginalGriff 6,080
1 DamithSL 4,648
2 Maciej Los 4,087
3 Kornfeld Eliyahu Peter 3,624
4 Sergey Alexandrovich Kryukov 3,294


Advertise | Privacy | Mobile
Web01 | 2.8.141220.1 | Last Updated 19 Sep 2011
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100