热点推荐:ASP.Net | ADO.Net | VB.Net | Web服务器 | Access | MSSQL | MySQL | Oracle | .Net控件 | Win 9x | Win 2000 | Win 2003 | DOS | Unix | 注册表 | 应用其它 | 安装调试 | 基本操作 | 使用技巧 | 系统优化 |故障处理 | 个性风格 | 病毒安全 | 专杀工具
您现在的位置: 中华IT技术网 >> FAQ >> C/C++ >> C语言 >> 正文
全文
VC中使用ini文件的方法
作者:1024k    文章来源:Web    更新时间:2007-6-15

怎样在VC++6.0中直接操作ini文件。100分恭候!
---------------------------------------------------------------

有很多api函数可直接读取ini文件的,比如:
UINT GetPrivateProfileInt(
  LPCTSTR lpAppName,  // section name
  LPCTSTR lpKeyName,  // key name
  INT nDefault,       // return value if key name not found
  LPCTSTR lpFileName  // initialization file name
);
DWORD GetPrivateProfileSection(
  LPCTSTR lpAppName,        // section name
  LPTSTR lpReturnedString,  // return buffer
  DWORD nSize,              // size of return buffer
  LPCTSTR lpFileName        // initialization file name
);
DWORD GetPrivateProfileSectionNames(
  LPTSTR lpszReturnBuffer,  // return buffer
  DWORD nSize,              // size of return buffer
  LPCTSTR lpFileName        // initialization file name
);
DWORD GetPrivateProfileString(
  LPCTSTR lpAppName,        // section name
  LPCTSTR lpKeyName,        // key name
  LPCTSTR lpDefault,        // default string
  LPTSTR lpReturnedString,  // destination buffer
  DWORD nSize,              // size of destination buffer
  LPCTSTR lpFileName        // initialization file name
);
DWORD GetPrivateProfileString(
  LPCTSTR lpAppName,        // section name
  LPCTSTR lpKeyName,        // key name
  LPCTSTR lpDefault,        // default string
  LPTSTR lpReturnedString,  // destination buffer
  DWORD nSize,              // size of destination buffer
  LPCTSTR lpFileName        // initialization file name
);
详细请看msdn
---------------------------------------------------------------

给你一个简单的示例:
CString strSection       = "My Section";
   CString strStringItem    = "My String Item";
   CString strIntItem       = "My Int Item";

   CWinApp* pApp = AfxGetApp();

   pApp->WriteProfileString(strSection, strStringItem, "test");

   CString strValue;
   strValue = pApp->GetProfileString(strSection, strStringItem);
   ASSERT(strValue == "test");

   pApp->WriteProfileInt(strSection, strIntItem, 1234);
   int nValue;
   nValue = pApp->GetProfileInt(strSection, strIntItem, 0);
   ASSERT(nValue == 1234);

相关文章
最新更新
编辑推荐
热门图片
频道大全
文章阅读排行
周排行
月排行