//先选择Project|setting命令下Project setting命令下对话框,在Microsoft Foundation Classes下选择 Use MFC in a Shared DLL
#include<iostream.h>
#include<afx.h>
//#include<afx1.h>
#define MAX_ALLSECTIONS 300 //定义最大的段长度
#define MAX_SECTION 20 //段的最大长度
void main()
{
//2、节与健的枚举
/* 1 健
DWORD GetPrivateProfileSection(
LPCTSTR lpAppName, // section name
LPTSTR lpReturnedString, // return buffer
DWORD nSize, // size of return buffer
LPCTSTR lpFileName // initialization file name
);
2 节
DWORD GetPrivateProfileSectionNames(
LPTSTR lpszReturnBuffer, // return buffer
DWORD nSize, // size of return buffer
LPCTSTR lpFileName // initialization file name
);
*/
int i;
int pos=0;
//CString str;
char chSectionNames[MAX_ALLSECTIONS]={0};//总的提出来的字符串
char chSection[MAX_SECTION]={0};//存放一个小节名
char chKey[MAX_SECTION]={0};
//LPCTSTER lpFileName="";
GetPrivateProfileSectionNames(chSectionNames,MAX_ALLSECTIONS,lpFileName);
//cout<<chSectionNames<<endl;
for(i=0;i<MAX_ALLSECTIONS-1;i++)
{
/*
if(chSectionNames[i]==0 && chSectionNames[i+1]!=0)//得到前面段明
{
for(int m=pos;m<=i;m++)
{
chSection[m-pos]=chSectionNames[m];//获取小节名
}
pos=i+1;
str.Format("%s",chSection);
cout<<str<<endl;
}
if(chSectionNames[i]==0&&chSectionNames[i+1]==0)//得到最后一个小节名
{
for(int m=pos;m<=i;m++)
{
chSection[m-pos]=chSectionNames[m];
}
str.Format("%s",chSection);
cout<<str<<endl;
break;
}*/
if(chSectionNames[i]==0)//得到前面段明
{
for(int m=pos;m<=i;m++)
{
chSection[m-pos]=chSectionNames[m];//获取小节名
}
str.Format("%s",chSection);
cout<<str<<endl;
//获取键值
GetPrivateProfileSection(chSection,chKey,MAX_SECTION,lpFileName);
str.Format("%s",chKey);
cout<<str<<endl;
if(chSectionNames[i+1]!=0)
{
pos=i+1;
}
else
{
break;
}
}
}
}