Save file settings in ini instead of registry

I am new to MFC as soon as I create my first application, in myApp :: InitInstance (). I have

SetRegistryKey(_T("Local AppWizard-Generated Applications")); 

Can I remove this and save the settings in my own ini construct?

+2
source share
4 answers

Edit: After further testing, the solution below does not work if your application class is derived from CWinAppEx ! It works if your application is directly obtained from CWinApp .


To save values ​​in a .ini file instead of a registry:

  • SetRegistryKey call to SetRegistryKey .
  • In your application class, set m_pszProfileName to the full path to your .ini file. The file name string should be allocated using malloc , because the framework will call free when your application shuts down. First, the existing value is free , then assign a new line:

    free((void*)m_pszProfileName);
    m_pszProfileName = ::_tcsdup(_T("C:\\somedir\\myini.ini"));

  • Call CWinApp::GetProfileInt , CWinApp::WriteProfileInt and similar functions as usual.

I highly recommend using the path in APPDATA to store your .ini file.

+7
source

Yes, you can. CWinApp :: SetProfileXXX () does this for you, actually, but I will no longer use these methods in 2010, they were fine when ppl moved from .ini to the registry.

+2
source

I'm not sure if this is possible, since the .ini file has only lines for your program. You can create a script operating system (.bat for windows, .sh for unix, etc.) and invoke it by calling system ().

+1
source

Use the win32 WriteProfileString APIs (write to the INI file) and GetProfileString (read from the INI file) For more information, ms help: //MS.MSDNQTR.v90.en/sysinfo/base/writeprofilestring.htm

+1
source

All Articles