Home > Software engineering >  MFC program reads the configuration file?
MFC program reads the configuration file?

Time:10-01

Reading configuration file first before setting the configuration file path is as follows:
 CWinApp * pApp=(CWinApp *) AfxGetApp (); 
Free ((void *) pApp - & gt; M_pszProfileName);
PApp - & gt; M_pszProfileName=_tcsdup (_T (" stock. INI "));

The next step is to read and write configuration file

Problem is m_pszProfileName configuration file path to write wrong, even do not specify a configuration file path, the program can read and write properly, according to the configuration file and obviously this is not for my presupposition of configuration files, some people say that do not specify a configuration file path, online reading system configuration files Win by default. INI, but Win. No I want to read and write INI the related fields of ah, is really puzzling I don't know which friend have relevant experience, pray tell, thank you!

CodePudding user response:

Not specified, the data is saved to the registry

In addition _tcsdup (_T (" stock. INI ")); Write an absolute path, when

CodePudding user response:

Did you keep the ini in the current directory then blind cat you encounter dead mouse tracking system under open the return value of bai

CodePudding user response:

GetCurrentDirectory
SetCurrentDirectory

CodePudding user response:

There are so difficult to get the current exe directory

CodePudding user response:

 
Cstrings GetApplicationPath (cstrings strFileName)
{
TCHAR strRet [MAX_PATH]={0};
GetModuleFileName (NULL, strRet MAX_PATH);
(_tcsrchr (strRet, _T (' \ \ '))) [1]=0;
Cstrings strPath=_T (" ");
For (int n=0; StrRet [n]. N++)
{
If (strRet [n].=_T (' \ \ ')) + strPath=strRet [n].
The else strPath +=_T (" \ \ \ \ ");
}
+ strPath=strFileName;
If (strPath==_T (" ")) return _T (" ");
Return strPath;
}

CodePudding user response:

Estimation is to read the registry, you also in the operation of the registry, if read local, convenient to debug, read directly using absolute path, upstairs has a path for function
  • Related