VC++2005 MFC INI文件的操作

VC++2005编程

VC++2005 MFC INI文件的操作

作者:邵盛松 2008年10月5日星期日

INI文件用于初始化程序

格式为

[Section]
Key=Value

写操作函数为

BOOL WritePrivateProfileString(LPCTSTR lpAppName, // 节 Section
     LPCTSTR lpKeyName, // 项 Key
    LPCTSTR lpString, // 值 Value
    LPCTSTR lpFileName // INI文件路径
     );
读操作函数

DWORD GetPrivateProfileString(LPCTSTR lpAppName, // 节
     LPCTSTR lpKeyName, // 项
     LPCTSTR lpDefault, // 缺省字符串
     LPTSTR lpReturnedString, // 存放字符串的缓冲区地址
     DWORD nSize, // 缓冲区大小
     LPCTSTR lpFileName //  INI文件路径
      );

 


 
 CString s;
 CString sPath(_T("c://SoftConfig.ini"));
 WritePrivateProfileStringW(_T("Section1"), _T("Key1"),_T("Value1"), sPath);
 WritePrivateProfileStringW(_T("Section2"), _T("Key2"),_T("Value2"), sPath);
 WritePrivateProfileStringW(_T("Section3"), _T("Key3"),_T("Value3"), sPath);
 GetPrivateProfileStringW(_T("Section2"),_T("Key2"),_T(""),s.GetBuffer(MAX_PATH),MAX_PATH,sPath);
 MessageBox(s,_T("读取数据"),MB_OK);

你可能感兴趣的:(VC++2005 MFC INI文件的操作)