Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

What is the equivalent of savesetting and getsetting of VB in C++?

Status
Not open for further replies.

kaidetot

Programmer
Jun 9, 2003
4
PH
I'm new in C++ i need to know how to save and get data drom windows registry. pls help me. thanx.
 
in MFC look up CRegistry

or if you using standard API calls lookup

RegOpenKeyEx
RegQueryValueEx
RegSetValueEx
RegCloseKey

heres 2 functions i wrote in my own registry class, i dunno how good they are, but they work and are probably a useful start for you...

CRegistry::CRegistry()
{
char* pDefaultKey = "Software\\Unknown App\\Settings";
m_hRootKey = HKEY_LOCAL_MACHINE;
m_cSubKey = (char *)malloc((strlen(pDefaultKey) + 1) * sizeof(char));
strcpy(m_cSubKey, pDefaultKey);
m_hRegKey = NULL;
m_ulDataSize = 0;
}

bool CRegistry::OpenKey(char* KeyName, int* Value)
{
if (RegOpenKeyEx(m_hRootKey, m_cSubKey, 0, KEY_ALL_ACCESS, &m_hRegKey) == ERROR_SUCCESS)
{
// Successfully opened the key
m_ulDataSize = sizeof(DWORD);
if (RegQueryValueEx(m_hRegKey, KeyName, NULL, NULL, (LPBYTE)Value, (LPDWORD)&m_ulDataSize) == ERROR_SUCCESS)
{
RegCloseKey(m_hRegKey);
return true;
}
}
return false;
}

bool CRegistry::SaveKey(char* KeyName, char* Value)
{
unsigned long ulIsNew = 0;
HKEY hRegKey;

if (RegCreateKeyEx(m_hRootKey, m_cSubKey, NULL, NULL, NULL, KEY_WRITE, NULL, &hRegKey, &ulIsNew) == ERROR_SUCCESS)
{
if (RegSetValueEx(hRegKey, KeyName, 0, REG_SZ, (const BYTE *)Value, (DWORD)strlen(Value)) == ERROR_SUCCESS)
{
RegCloseKey(hRegKey);
return true;
}
}
return false;
}
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top