I'm new to MFC, once I create my first app, in myApp::InitInstance() . I have
SetRegistryKey(_T("Local AppWizard-Generated Applications"));
Can I delete this and save settings to my own ini construct ?
I'm new to MFC, once I create my first app, in myApp::InitInstance() . I have
SetRegistryKey(_T("Local AppWizard-Generated Applications"));
Can I delete this and save settings to my own ini construct ?
Use win32 APIs WriteProfileString (write to INI file) and GetProfileString (read from INI file) For more help ms-help://MS.MSDNQTR.v90.en/sysinfo/base/writeprofilestring.htm
Yes you can. CWinApp::SetProfileXXX() does this for you, actually - but I wouldn't use these methods anymore in 2010, they were OK when ppl moved from .ini to the registry.
I am not sure if this is possible as a .ini file has only strings for your program. You can create an operating system script (.bat for windows, .sh for unix etc) and call it using system() call.
Edit: After further testing, the solution below does not work if your app class is derived from
CWinAppEx
! It does work if your app is directly derived fromCWinApp
.To store values in an
.ini
file instead of the registry:SetRegistryKey
.In your app class, set
m_pszProfileName
to the full path of your.ini
file. The filename string must be allocated usingmalloc
, because the framework will callfree
on it when your app shuts down. Firstfree
the existing value, then assign your new string:free((void*)m_pszProfileName);
m_pszProfileName = ::_tcsdup(_T("C:\\somedir\\myini.ini"));
Call
CWinApp::GetProfileInt
,CWinApp::WriteProfileInt
and similar functions as usual.I strongly recommend using a path under APPDATA for storing your
.ini
file.