MFC读取.ini文件的方法

来源:互联网 发布:centos 7中文 编辑:程序博客网 时间:2024/04/19 16:16
  1. TCHAR tchBuffer[MAX_PATH];
  2. LPWSTR curPath;
  3. curPath = tchBuffer;
  4. GetCurrentDirectory(MAX_PATH,curPath);
  5. CString fileName("//sys.ini");
  6. CString path(curPath);
  7. path = path + fileName;
  8. ::GetPrivateProfileString(L"init",L"Server",L"Localhost",this->server.GetBuffer(20),20,path);
  9. ::GetPrivateProfileString(L"init",L"UID",L"sa",this->UID.GetBuffer(20),20,path);
  10. ::GetPrivateProfileString(L"init",L"PWS",L"sa",this->PWD.GetBuffer(20),20,path);
  11. ::GetPrivateProfileString(L"init",L"DefaultDB",L"master",this->DefaultDB.GetBuffer(20),20,path);
 获取文件路径后,使用GetPrivateProfileString函数读取文件内容
参数解释:
0:区域([])中的字符串
1:key
2:默认值,若没有找到文件或区域或key这使用默认值
3:存放值的地址
4:大小
5:ini文件路径
原创粉丝点击