Note the method for reading the. ini configuration file.
In practice, the path to the current program (or a specific profile directory) is usually first obtained.
GetModuleFileName
Explain this sentence: STRRCHR (cfgpath, ' \ \ ') [0] = ' n ';
STRRCHR (cfgpath, ' \ \ ') returns the last occurrence of the ' \ ' in the path, STRRCHR (Cfgpath, ' \ \ ') [0] changes the position to '. After strcat, the absolute address of the configuration file is obtained.
Getprivateprofilestringa (Here is the string, there are other types) is to get the configuration file corresponding to the function, it must be absolute path.
Char Cfgpath[max_path];
int bdenoise = 0;
if (GetModuleFileNameA (NULL, Cfgpath, MAX_PATH) > 0)
{
strrchr (cfgpath, ' \ \ ') [0] = ';
strcat (Cfgpath, "\\config.ini");
Char tmp[8];
Getprivateprofilestringa ("Denoise", "Denoise", "0", TMP, 8, cfgpath);
Bdenoise = atoi (TMP);
}
There is also a wide-character notation:
TCHAR Inifullpath[max_path];
if (GetModuleFileName (NULL, Inifullpath, MAX_PATH) > 0)
{
(_TCSRCHR (Inifullpath, _t (' \ \ \))] [1] = 0;
Wstring strpath = Inifullpath;
strpath = strpath + _t ("Config.ini");
Bdenoise = Getprivateprofileint (L "denoise", L "Denoise", 0, Strpath.c_str ());