INI文件的基本操作

    INI文件的結構非簡單,主要包括3個要素,即: 1、段落(節):即方括號[]中的名稱;2、關鍵字名:某節中一個獨有的字串,即一個變量;3、關鍵字值:即變量的值。

    注意點:1、各行必須頂格開式書寫;2、=號緊跟關鍵字;3、註釋在行首以“;”開頭。

    Win32提供了特定的Window API函數用於操作INI文件。現在介紹幾個主要常用的讀寫函數:

DWORD GetPrivateProfileString(       // Read
              LPCTSTR lpAppName,      //節名
              LPCTSTR lpKeyName,      //關鍵字名
              LPCTSTR lpDefault,         //關鍵字默認值
              LPCTSTR lpReturnedString,     //目標返回字符串
              DWORD nSize,     //字符串長
              LPCTSTR lpFileName        //INI文件名
);
UINT GetPrivateProfileInt(                        
//Read
              LPCTSTR lpAppName,  // section name
              LPCTSTR lpKeyName,  // key name
              INT nDefault,       // return value if key name not found
              LPCTSTR lpFileName  // initialization file name
); 
BOOL WritePrivateProfileString(                        
//Write
              LPCTSTR lpAppName,  // section name
              LPCTSTR lpKeyName,  // key name
              LPCTSTR lpString,   // string to add
              LPCTSTR lpFileName  // initialization file
);             

 

 

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章