I want to create a key in the Registry Editor of Windows XP using c++ program.
After this i am to write the Name and the Data(e.g value) of that particular key using c++ program.
And i am to read the Name and Data(Value) of that particular key using c++ program.

Please help me regarding this issue.
I am doing it of my own....

i am trying my self to create KEY in Registry Editor through c++ program but when i run my program, "not successfully create key"..
i am using REGCreate(...) but still key is not creating,

Plz if u have any idea, describe with me in your own words...

Here is an example of how to create a key. Make sure you read the Remarks section of this link

#include <Windows.h>
#include <iostream>
using std::cout;

int main(int argc, char* argv[])
{
	HKEY hKey = 0;
	DWORD dwDisposition = 0;
	long retval = RegCreateKeyEx(HKEY_CURRENT_USER,"Software\\Ancient Dragon",0,0,REG_OPTION_NON_VOLATILE,
				KEY_ALL_ACCESS,0,&hKey,&dwDisposition);
	if( retval !=  ERROR_SUCCESS)
	{
		char buf[255] = {0};
		DWORD dwError = GetLastError();
		FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM,0,dwError,0,buf,sizeof(buf),0);
		cout << buf << '\n';
	}
	else
	{
		RegCloseKey(hKey);
		cout << dwDisposition << '\n';
	}
	return 0;
}

yes!!!! its working successFully....
Thanks dear,
Now i have done Create Key, setvalue, and reading Value from key....

Again Thanks.....

Problem to increment key value
now i want to increment key value at run-time, i am trying but nothing solved this problem yet.
e.g. when i run program the key-value is 1, and i want that when i run this program again the key-value should be 2...

plz help me for this problem

Simple solution -- each time the program starts it updates the key value with a new value. Call RegQueryValue() to get the current value, increment the counter, then RegSetKeyValue() to update it.

Call these functions in the order listed. You will have to do error checking to insure they succeed.
RegOpenKeyEx()
RegQueryValue()
RegSetKeyValue()
RegCloseKey()

Thanx for reply,
But i solve this problem myself before your reply...
And i also solve my problem through RgOpenKeyEx() as u said....

But Thanx for reply because your posts are useful for me & others...

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.