#include <vector>
#include <string>
#include <iostream>
#include <Windows.h>
#include <Shlwapi.h>
#pragma comment(lib,"shlwapi.lib")
std::vector<std::string> m_sections;
int _tmain(int argc, _TCHAR* argv[])
{
char szModule[MAX_PATH] = {0};
GetModuleFileName(NULL,szModule,MAX_PATH);
PathRemoveFileSpec(szModule);
PathAppend(szModule,"SoftInfo.ini");
char sections[2000] ={0};
GetPrivateProfileSectionNames(sections,2000,szModule);
char szSection[MAX_PATH] = {0};
int iPos = 0;
for (int i=0; i<2000; ++i)
{
if (szSection[0] != '\0' && '\0' == sections[i+1] && '\0' == sections[i+2])
{
szSection[iPos]=0;
m_sections.push_back(szSection);
break;
}
szSection[iPos++] = sections[i];
if ('\0' == sections[i])
{
iPos = 0;
m_sections.push_back(szSection);
ZeroMemory(szSection, MAX_PATH);
}
}
for (int i=0; i< m_sections.size(); ++i)
{
char softName[MAX_PATH] = {0};
GetPrivateProfileString(m_sections[i].c_str(),"SoftName","",softName,MAX_PATH,szModule);
std::cout<<softName<<std::endl;
}
std::cout<<"*********************************************"<<std::endl;
system("pause");
return 0;
}
上面的代码打印出了程序所在目录的SoftInfo.ini中所有区块的SoftName字段的键值