16,471
社区成员
发帖
与我相关
我的任务
分享
/******************************************************************
* 函数名称: GetCfgData
* 功能描述: 读取配置文件的数据
***********************************************************************/
CString GetCfgData(const CString strAppName, const CString strKeyName, const CString IniFileName)
{
TRACE_FUNCTION_DEBUG
CString strData;
// 获得配置文件的路径
TCHAR sDir[1000];
GetModuleFileName(NULL, sDir, 1000);
CString strFile;
strFile.Format(_T("%s"), sDir);
int iFinder = strFile.ReverseFind('\\');
if (iFinder > 0)
{
strFile = strFile.Left(iFinder+1);
strFile += IniFileName;
}
TCHAR cValue[200];
memset(cValue, 0, 200);
// 读取频率值
GetPrivateProfileString(strAppName, strKeyName, _T(""), cValue, 200, strFile);
strData.Format(_T("%s"), cValue);
return strData;
}
/******************************************************************
* 函数名称: SetCfgData
* 功能描述: 写配置文件的数据
***********************************************************************/
void SetCfgData(const CString strAppName, const CString strKeyName, const CString strValue,const CString IniFileName)
{
TRACE_FUNCTION_DEBUG
// 获得配置文件的路径
TCHAR sDir[1000];
GetModuleFileName(NULL, sDir, 1000);
CString strFile;
strFile.Format(_T("%s"), sDir);
int iFinder = strFile.ReverseFind('\\');
if (iFinder > 0)
{
strFile = strFile.Left(iFinder+1);
strFile += IniFileName;
}
WritePrivateProfileString(strAppName,strKeyName,strValue,strFile);
return ;
}