making ini file in Documents and Settings WritePrivateProfileString to
-
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?
-
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?
-
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?
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++) -
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?
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: //
************* -
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: //
*************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