Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. INI insted of Registry

INI insted of Registry

Scheduled Pinned Locked Moved C / C++ / MFC
c++windows-admintutorialquestion
3 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    Abhijeet Pathak
    wrote on last edited by
    #1

    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?

    J H 2 Replies Last reply
    0
    • A Abhijeet Pathak

      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?

      J Offline
      J Offline
      Joan M
      wrote on last edited by
      #2

      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.

      https://www.robotecnik.com freelance robots, PLC and CNC programmer.

      1 Reply Last reply
      0
      • A Abhijeet Pathak

        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?

        H Offline
        H Offline
        Hans Dietrich
        wrote on last edited by
        #3

        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:

        1. 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";
          
        2. 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);
          
        3. 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 Document

          WriteProfileString("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]

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups