INI insted of Registry
-
Hi, Whenever we generate a MFC app, it generates standard skeleton and code for storing options and MRU in the registry in the
BOOL CSampleApp::InitInstance()
function.SetRegistryKey(_T("SampleApp")); LoadStdProfileSettings(0); // Load standard INI file options (including MRU)
The above comment suggests that options can be loaded either from INI or registry, and by default registry is used. How to activate the use of INI files insted of registry. I'm using VS2005. Thanks -- Why buy the cow when milk is free? -
Hi, Whenever we generate a MFC app, it generates standard skeleton and code for storing options and MRU in the registry in the
BOOL CSampleApp::InitInstance()
function.SetRegistryKey(_T("SampleApp")); LoadStdProfileSettings(0); // Load standard INI file options (including MRU)
The above comment suggests that options can be loaded either from INI or registry, and by default registry is used. How to activate the use of INI files insted of registry. I'm using VS2005. Thanks -- Why buy the cow when milk is free?One INI file is a standard file, you should search the MSDN or here in the CP in order to get more information on how to open, read, write and close files. I would recommend you to use XML files instead of ini files... but this is only a matter of preferences... If you would like to go to the XML way you should learn how to use any of the interfaces that are in the market. Hope this helps.
-
Hi, Whenever we generate a MFC app, it generates standard skeleton and code for storing options and MRU in the registry in the
BOOL CSampleApp::InitInstance()
function.SetRegistryKey(_T("SampleApp")); LoadStdProfileSettings(0); // Load standard INI file options (including MRU)
The above comment suggests that options can be loaded either from INI or registry, and by default registry is used. How to activate the use of INI files insted of registry. I'm using VS2005. Thanks -- Why buy the cow when milk is free?You can easily switch to using INI files. The major problem you will have is deciding where to put them - Microsoft discourages writing into any of the C:\Program Files folders, which is where your app will usually be installed. But, once you know where you want it, switching to INI file is easy:
-
Construct path to INI file:
BOOL CApp::InitInstance()
{
.
.
.
m_strProfileFilePath = ""; // m_strProfileFilePath is CString member of CApp// let's put INI in exe directory m\_strProfileFilePath = GetModulePath(); m\_strProfileFilePath += "\\\\"; m\_strProfileFilePath += "MyApp.ini";
-
Next we need to clean up MFC's default INI string:
// save our ini file name -- // first free the string allocated by MFC at CWinApp startup. // The string is allocated before InitInstance is called. free((void\*)m\_pszProfileName); // Change the name of the .INI file. // The CWinApp destructor will free the memory. // Note: must be allocated on heap m\_pszProfileName = \_strdup(m\_strProfileFilePath);
-
Now we can use the standard profile functions in CWinApp:
// write some stuff to INI file
// [FilesToAdd]
// File001=CRASH.DMP,Crash Dump,DMP File
// File002=ERRORLOG.TXT,Crash log,Text Document
// File003=MyApp.ini,INI File,Text DocumentWriteProfileString("FilesToAdd", "File001", "CRASH.DMP,Crash Dump,DMP File"); WriteProfileString("FilesToAdd", "File002", "ERRORLOG.TXT,Crash log,Text Document"); WriteProfileString("FilesToAdd", "File003", "MyApp.ini,INI File,Text Document"); . . .
Best wishes, Hans
[CodeProject Forum Guidelines] [How To Ask A Question] [My Articles]
-