.ini配置文件的存取

来源:互联网 发布:南京逍遥游网络怎么样 编辑:程序博客网 时间:2024/05/16 04:11

 TCHAR exeFullPath[MAX_PATH]; // MAX_PATH在API中有定义,为128 int len=GetModuleFileName(NULL, exeFullPath, //应用程序的全路径存放地址 MAX_PATH); CString path="//config.ini"; //配置文件名 ::strcpy(exeFullPath+len-12,path); //组合出配置文件的全路径

//读取

    CString szComCheck ; CString szBaud ; GetPrivateProfileString("短信中心号码", "SMSC","+8613800280500", strSMSC.GetBuffer(MAX_PATH),MAX_PATH,exeFullPath);    GetPrivateProfileString("IP地址", "IP","127.0.0.1",strIP.GetBuffer(MAX_PATH),MAX_PATH,exeFullPath); GetPrivateProfileString("网络端口号", "NetPort","",strNetPort.GetBuffer(MAX_PATH),MAX_PATH,exeFullPath); GetPrivateProfileString("定时周期", "TimeCycle","",strTimeCycle.GetBuffer(MAX_PATH),MAX_PATH,exeFullPath);    for(int i=0; i<8; i++) {     szComCheck.Format("COMCheck%d",i);  GetPrivateProfileString("串口选中状态", szComCheck,"0", strCheck[i].GetBuffer(MAX_PATH),MAX_PATH,exeFullPath);  szBaud.Format("Baud%d",i);  GetPrivateProfileString("波特率", szBaud ,"9600", strBaud[i].GetBuffer(MAX_PATH),MAX_PATH,exeFullPath); }

 

 TCHAR exeFullPath[MAX_PATH]; // MAX_PATH在API中有定义,为128 int len=GetModuleFileName(NULL, exeFullPath, //应用程序的全路径存放地址 MAX_PATH); CString path="//Config.ini"; //配置文件名 ::strcpy(exeFullPath+len-12,path); //组合出配置文件的全路径

//存入        CString szComCheck ; CString szBaud ; WritePrivateProfileString("短信中心号码", "SMSC", strSMSC,exeFullPath);    WritePrivateProfileString("IP地址", "IP",strIP,exeFullPath); WritePrivateProfileString("网络端口号", "NetPort",strNetPort,exeFullPath); WritePrivateProfileString("定时周期", "TimeCycle",strTimeCycle,exeFullPath);    for(int i=0; i<8; i++) {     szComCheck.Format("COMCheck%d",i);  WritePrivateProfileString("串口选中状态", szComCheck, strCheck[i],exeFullPath);  szBaud.Format("Baud%d",i);  WritePrivateProfileString("波特率", szBaud , strBaud[i],exeFullPath); }