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
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. making ini file in Documents and Settings WritePrivateProfileString to

making ini file in Documents and Settings WritePrivateProfileString to

Scheduled Pinned Locked Moved C / C++ / MFC
question
5 Posts 5 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.
  • M Offline
    M Offline
    malaugh
    wrote on last edited by
    #1

    I am trying to make an INI file in C:\Documents and Settings\All Users\Application Data\MyApp I know WritePrivateProfileString will write a new file if one does not exist, but if I try

    #define INI_FILENAME "C:\\Documents and Settings\\All Users\\Application Data\\MyApp\\MyApp.ini"

    WritePrivateProfileString("My Section", "My Name", "My Value", INI_FILENAME);

    It will only make a new ini file if the directory exists. Is there a workaround for this? If not, how do I check to see if a directory exists, and make a new one?

    PJ ArendsP _ W 3 Replies Last reply
    0
    • M malaugh

      I am trying to make an INI file in C:\Documents and Settings\All Users\Application Data\MyApp I know WritePrivateProfileString will write a new file if one does not exist, but if I try

      #define INI_FILENAME "C:\\Documents and Settings\\All Users\\Application Data\\MyApp\\MyApp.ini"

      WritePrivateProfileString("My Section", "My Name", "My Value", INI_FILENAME);

      It will only make a new ini file if the directory exists. Is there a workaround for this? If not, how do I check to see if a directory exists, and make a new one?

      PJ ArendsP Offline
      PJ ArendsP Offline
      PJ Arends
      wrote on last edited by
      #2

      malaugh wrote:

      how do I check to see if a directory exists, and make a new one?

      SHCreateDirectoryEx


      You may be right I may be crazy -- Billy Joel -- Within you lies the power for good - Use it!

      Within you lies the power for good; Use it!

      1 Reply Last reply
      0
      • M malaugh

        I am trying to make an INI file in C:\Documents and Settings\All Users\Application Data\MyApp I know WritePrivateProfileString will write a new file if one does not exist, but if I try

        #define INI_FILENAME "C:\\Documents and Settings\\All Users\\Application Data\\MyApp\\MyApp.ini"

        WritePrivateProfileString("My Section", "My Name", "My Value", INI_FILENAME);

        It will only make a new ini file if the directory exists. Is there a workaround for this? If not, how do I check to see if a directory exists, and make a new one?

        _ Offline
        _ Offline
        _Superman_
        wrote on last edited by
        #3

        SHCreateDirectory can create the full path with just one call.

        «_Superman_» I love work. It gives me something to do between weekends.
        Microsoft MVP (Visual C++)

        1 Reply Last reply
        0
        • M malaugh

          I am trying to make an INI file in C:\Documents and Settings\All Users\Application Data\MyApp I know WritePrivateProfileString will write a new file if one does not exist, but if I try

          #define INI_FILENAME "C:\\Documents and Settings\\All Users\\Application Data\\MyApp\\MyApp.ini"

          WritePrivateProfileString("My Section", "My Name", "My Value", INI_FILENAME);

          It will only make a new ini file if the directory exists. Is there a workaround for this? If not, how do I check to see if a directory exists, and make a new one?

          W Offline
          W Offline
          wangningyu
          wrote on last edited by
          #4

          the window sdk's function to operation "*.ini", like function WritePrivateProfileString and more,it's very inconvenient. so you can use this class in your program (if the section isn't exiting,it will create himself.)

          // ***************************************************************
          // OPini.h: interface for the COPini class.
          // -------------------------------------------------------------
          // this class will read the "*.ini" file from the current path.
          // -------------------------------------------------------------
          // ***************************************************************

          #if !defined(AFX_OPINI_H__CE3F8B7B_1ACA_46CC_A91C_F8E23FA9B063__INCLUDED_)
          #define AFX_OPINI_H__CE3F8B7B_1ACA_46CC_A91C_F8E23FA9B063__INCLUDED_
          #if _MSC_VER > 1000
          #pragma once
          #endif // _MSC_VER > 1000

          #include
          class COPini
          {
          public:
          static DWORD ReadString (char *section, char * key, char stringtoread[], char * filename);
          static BOOL WriteString(LPCTSTR section, LPCTSTR key,char* stringtoadd, char *filename);
          COPini();
          virtual ~COPini();

          };

          #endif // !defined(AFX_OPINI_H__CE3F8B7B_1ACA_46CC_A91C_F8E23FA9B063__INCLUDED_)

          // OPini.cpp: implementation of the COPini class.
          //
          //////////////////////////////////////////////////////////////////////
          #include "stdafx.h"
          #include "OPini.h"

          /********************************************************************
          filename: // OPini.cpp
          file path:
          file base: // OPini
          file ext: // cpp
          author: // alantop
          purpose: // 读取INI文件。
          *********************************************************************/
          //////////////////////////////////////////////////////////////////////
          // Construction / Destruction
          //////////////////////////////////////////////////////////////////////

          COPini::COPini()
          {
          }
          COPini::~COPini()
          {
          }
          void error(LPSTR lpszFunction)
          {
          CHAR szBuf[80];
          DWORD dw = GetLastError();
          sprintf(szBuf, "%s failed: GetLastError returned %u\n",
          lpszFunction, dw);
          MessageBox(NULL, szBuf, "Error", MB_OK);
          ExitProcess(dw);
          }

          /*****************************************************************************
          Function: //
          Description: // write the config fto the "*.ini" files.
          Calls: //
          Called By: //
          Table Accessed: //
          Table Updated: //
          Input: //
          Output: //
          Return: // If success it will return TRUE ,else return FALSE.
          Others: //
          author: //
          *************

          D 1 Reply Last reply
          0
          • W wangningyu

            the window sdk's function to operation "*.ini", like function WritePrivateProfileString and more,it's very inconvenient. so you can use this class in your program (if the section isn't exiting,it will create himself.)

            // ***************************************************************
            // OPini.h: interface for the COPini class.
            // -------------------------------------------------------------
            // this class will read the "*.ini" file from the current path.
            // -------------------------------------------------------------
            // ***************************************************************

            #if !defined(AFX_OPINI_H__CE3F8B7B_1ACA_46CC_A91C_F8E23FA9B063__INCLUDED_)
            #define AFX_OPINI_H__CE3F8B7B_1ACA_46CC_A91C_F8E23FA9B063__INCLUDED_
            #if _MSC_VER > 1000
            #pragma once
            #endif // _MSC_VER > 1000

            #include
            class COPini
            {
            public:
            static DWORD ReadString (char *section, char * key, char stringtoread[], char * filename);
            static BOOL WriteString(LPCTSTR section, LPCTSTR key,char* stringtoadd, char *filename);
            COPini();
            virtual ~COPini();

            };

            #endif // !defined(AFX_OPINI_H__CE3F8B7B_1ACA_46CC_A91C_F8E23FA9B063__INCLUDED_)

            // OPini.cpp: implementation of the COPini class.
            //
            //////////////////////////////////////////////////////////////////////
            #include "stdafx.h"
            #include "OPini.h"

            /********************************************************************
            filename: // OPini.cpp
            file path:
            file base: // OPini
            file ext: // cpp
            author: // alantop
            purpose: // 读取INI文件。
            *********************************************************************/
            //////////////////////////////////////////////////////////////////////
            // Construction / Destruction
            //////////////////////////////////////////////////////////////////////

            COPini::COPini()
            {
            }
            COPini::~COPini()
            {
            }
            void error(LPSTR lpszFunction)
            {
            CHAR szBuf[80];
            DWORD dw = GetLastError();
            sprintf(szBuf, "%s failed: GetLastError returned %u\n",
            lpszFunction, dw);
            MessageBox(NULL, szBuf, "Error", MB_OK);
            ExitProcess(dw);
            }

            /*****************************************************************************
            Function: //
            Description: // write the config fto the "*.ini" files.
            Calls: //
            Called By: //
            Table Accessed: //
            Table Updated: //
            Input: //
            Output: //
            Return: // If success it will return TRUE ,else return FALSE.
            Others: //
            author: //
            *************

            D Offline
            D Offline
            David Crow
            wrote on last edited by
            #5

            How does this help to create a non-existent folder structure? I think that SHCreateDirectoryEx() would be a better choice.

            "One man's wage rise is another man's price increase." - Harold Wilson

            "Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons

            "Man who follows car will be exhausted." - Confucius

            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