配置文件的读写

写配置文件:

wchar_t ModuleFileName[MAX_PATH] = { 0 };

::GetModuleFileName( NULL, ModuleFileName, MAX_PATH );

wchar_t* pPos = wcsrchr( ModuleFileName, L'\\' );

ModuleFileName[ pPos - ModuleFileName + 1 ] = L'\0';

std::wstring wstrINIFilePath(ModuleFileName);

wstrINIFilePath.append( L"kxWebview.ini");//获取配置文件的路径+名称

std::wstring wstrProjectPath;

wstrProjectPath.append(L"zhenjia.zhao");//配置文件中的配置名称

WritePrivateProfileString( L"UserName", L"UserName", wstrProjectPath.c_str(), wstrINIFilePath.c_str() );

读配置文件:

TCHAR ProductIniFileName[256] = {0};//配置文件路径

TCHAR strSetupLanguage[256]={0};//需要读取配置文件内容

::GetModuleFileName( NULL, ProductIniFileName, MAX_PATH );

::PathRemoveFileSpec( ProductIniFileName );//去掉配置文件应用名称

::PathAppend(ProductIniFileName,_T("kxWebview.ini"));//扩展

::GetPrivateProfileString(_T("UserName"),_T("UserName"),_T(""),strSetupLanguage,sizeof(strSetupLanguage),ProductIniFileName);

配置文件格式:名称 kxWebview.ini
[UserName]
UserName =a

你可能感兴趣的:(配置文件的读写)