essentialy i am trying to store a program setting in the registry that is a bool, 1 if certain things have been done before and 0 if they have not. ive read up some on readign and writing to the registry and it makes sense, but the little i have read did not go into enough detail for me to understand what it was i was doing so i have no clue how to write a simple bool value, i have read the MS thing on editing the registry which is right here:
Creating or Opening a Registry Key
Before you can read or write to a key, you must first obtain a handle to it. To do this, use either the RegOpenRegKeyEx or RegCreateKeyEx Microsoft Win32® functions. In practice, you will almost always use RegCreateKeyEx, which will open the key if it exists or create it if it does not. Here is a typical scenario:
Declare an HKEY variable in your code.
Call RegCreateKeyEx, passing HKEY_LOCAL_MACHINE as the parent key and Software/YourCompany/YourApplication as the subkey.
For each setting you wish to read, call RegQueryValueEx, and if the setting is not found set a default value.
Close the handle to the key with RegCloseKey.
Sample code:
void CMyFirstMFCApplicationApp::LoadPreferences()
{
HKEY hkey;
DWORD dwDisposition;
DWORD dwType, dwSize;
// Set the default values
m_dwMaxFileSize = 16 * 1024; // 16k
_tcscpy(m_szLastFileName, TEXT("Datafile.TXT");
if(RegCreateKeyEx(HKEY_LOCAL_MACHINE, TEXT("Software\\My Company\\My
Application", 0, NULL, 0, 0, NULL, &hkey, &dwDisposition)==
ERROR_SUCCESS)
{
dwType = REG_DWORD;
dwSize = sizeof(DWORD);
RegQueryValueEx(hkey, TEXT("MaxFileSize", NULL, &dwType,
(PBYTE)&m_dwMaxFileSize, &dwSize);
dwType = REG_SZ;
dwSize = sizeof(m_szLastFileName);
RegQueryValueEx(hkey, TEXT("LastFileName", NULL, &dwType,
(PBYTE)&m_szLastFileName, &dwSize);
RegCloseKey(hkey);
}
}
void CMyFirstMFCApplicationApp::SavePreferences()
{
HKEY hkey;
DWORD dwDisposition;
DWORD dwType, dwSize;
if(RegCreateKeyEx(HKEY_LOCAL_MACHINE, TEXT("Software\\My Company\\My
Application", 0, NULL, 0, 0, NULL, &hkey, &dwDisposition)==
ERROR_SUCCESS)
{
dwType = REG_DWORD;
dwSize = sizeof(DWORD);
RegSetValueEx(hkey, TEXT("MaxFileSize", 0, dwType,
(PBYTE)&m_dwMaxFileSize, dwSize);
dwType = REG_SZ;
dwSize = (_tcslen(m_szLastFileName) + 1) * sizeof(TCHAR);
RegSetValueEx(hkey, TEXT("LastFileName", 0, dwType,
(PBYTE)&m_szLastFileName, dwSize);
RegCloseKey(hkey);
}
}
that right there i think is supposed to write a string of text (id compile it now, but im at school and i dont think theyd want me editing the registry on these computers...). basicly i just need to know what all that stuff means. how i would go about reading a bool value from a specific key in the registry and returning it to a variable in the program and if it is 1 then skip some stuff, if it is 0 then do the stuff and when the stuff is done write a bool value to the registry to be read next time the program runs. im not totaly sure if this really matters... but im trying to do all this in a console program, not a win32 one or anything. i think all i need to include is windows.h, or is there something else i am forgetting? and if not can this be done in a console program. id do it in a win32 program but i dont know enough about that to make it do much of anything... (still learning right now).
Creating or Opening a Registry Key
Before you can read or write to a key, you must first obtain a handle to it. To do this, use either the RegOpenRegKeyEx or RegCreateKeyEx Microsoft Win32® functions. In practice, you will almost always use RegCreateKeyEx, which will open the key if it exists or create it if it does not. Here is a typical scenario:
Declare an HKEY variable in your code.
Call RegCreateKeyEx, passing HKEY_LOCAL_MACHINE as the parent key and Software/YourCompany/YourApplication as the subkey.
For each setting you wish to read, call RegQueryValueEx, and if the setting is not found set a default value.
Close the handle to the key with RegCloseKey.
Sample code:
void CMyFirstMFCApplicationApp::LoadPreferences()
{
HKEY hkey;
DWORD dwDisposition;
DWORD dwType, dwSize;
// Set the default values
m_dwMaxFileSize = 16 * 1024; // 16k
_tcscpy(m_szLastFileName, TEXT("Datafile.TXT");
if(RegCreateKeyEx(HKEY_LOCAL_MACHINE, TEXT("Software\\My Company\\My
Application", 0, NULL, 0, 0, NULL, &hkey, &dwDisposition)==
ERROR_SUCCESS)
{
dwType = REG_DWORD;
dwSize = sizeof(DWORD);
RegQueryValueEx(hkey, TEXT("MaxFileSize", NULL, &dwType,
(PBYTE)&m_dwMaxFileSize, &dwSize);
dwType = REG_SZ;
dwSize = sizeof(m_szLastFileName);
RegQueryValueEx(hkey, TEXT("LastFileName", NULL, &dwType,
(PBYTE)&m_szLastFileName, &dwSize);
RegCloseKey(hkey);
}
}
void CMyFirstMFCApplicationApp::SavePreferences()
{
HKEY hkey;
DWORD dwDisposition;
DWORD dwType, dwSize;
if(RegCreateKeyEx(HKEY_LOCAL_MACHINE, TEXT("Software\\My Company\\My
Application", 0, NULL, 0, 0, NULL, &hkey, &dwDisposition)==
ERROR_SUCCESS)
{
dwType = REG_DWORD;
dwSize = sizeof(DWORD);
RegSetValueEx(hkey, TEXT("MaxFileSize", 0, dwType,
(PBYTE)&m_dwMaxFileSize, dwSize);
dwType = REG_SZ;
dwSize = (_tcslen(m_szLastFileName) + 1) * sizeof(TCHAR);
RegSetValueEx(hkey, TEXT("LastFileName", 0, dwType,
(PBYTE)&m_szLastFileName, dwSize);
RegCloseKey(hkey);
}
}
that right there i think is supposed to write a string of text (id compile it now, but im at school and i dont think theyd want me editing the registry on these computers...). basicly i just need to know what all that stuff means. how i would go about reading a bool value from a specific key in the registry and returning it to a variable in the program and if it is 1 then skip some stuff, if it is 0 then do the stuff and when the stuff is done write a bool value to the registry to be read next time the program runs. im not totaly sure if this really matters... but im trying to do all this in a console program, not a win32 one or anything. i think all i need to include is windows.h, or is there something else i am forgetting? and if not can this be done in a console program. id do it in a win32 program but i dont know enough about that to make it do much of anything... (still learning right now).