ini文件的读取操作

ini文件的读取操作
通过这五个函数可以读出 .ini文件的int型value,string型value,所有的section,每个section的所有key字段,struct型value。
返回每个section的所有key字段时,返回值为写入的字符数,缓冲区内以'\0'为间隔符。
[section]
key1=int
key2=string
key3=struct
//************************************************************************
UINT GetPrivateProfileInt(
  LPCTSTR lpAppName,
  LPCTSTR lpKeyName,
  INT nDefault,
  LPCTSTR lpFileName
);
//********************************************************************
DWORD GetPrivateProfileSection(
  LPCTSTR lpAppName,
  LPTSTR lpReturnedString,
  DWORD nSize,
  LPCTSTR lpFileName
);
//********************************************************************
DWORD GetPrivateProfileSectionNames(
  LPTSTR lpszReturnBuffer,
  DWORD nSize,
  LPCTSTR lpFileName
);
//********************************************************************
DWORD GetPrivateProfileString(
  LPCTSTR lpAppName,
  LPCTSTR lpKeyName,
  LPCTSTR lpDefault,
  LPTSTR lpReturnedString,
  DWORD nSize,
  LPCTSTR lpFileName
);
//********************************************************************
BOOL GetPrivateProfileStruct(
  LPCTSTR lpszSection,
  LPCTSTR lpszKey,
  LPVOID lpStruct,
  UINT uSizeStruct,
  LPCTSTR szFile
);
//********************************************************************
ini文件的写入操作
BOOL WritePrivateProfileSection(
  LPCTSTR lpAppName,
  LPCTSTR lpString,
  LPCTSTR lpFileName
);
BOOL WritePrivateProfileString(
  LPCTSTR lpAppName,
  LPCTSTR lpKeyName,
  LPCTSTR lpString,
  LPCTSTR lpFileName
);
BOOL WritePrivateProfileStruct(
  LPCTSTR lpszSection,
  LPCTSTR lpszKey,
  LPVOID lpStruct,
  UINT uSizeStruct,
  LPCTSTR szFile
);
 

h=GetPrivateProfileSection("Directories",lpReturnedString,nSize,lpFileName);
 printf("%s\n%d\n%d\n",lpReturnedString,h,strlen(lpReturnedString));
 for(int i=0;i<h;i++)
 {
  printf("%c",lpReturnedString[i]=='\0' ? '\n':lpReturnedString[i]);
 }
 h=GetPrivateProfileSectionNames(lpReturnedString,nSize,lpFileName);
 printf("%s\n%d\n%d\n",lpReturnedString,h,strlen(lpReturnedString));
 for(int i=0;i<h;i++)
 {
   printf("%c",lpReturnedString[i]=='\0' ? '\n':lpReturnedString[i]);
 }
 typedef struct _mytest
 {
  int i;
  char a[30];
  double d;
 }mytest;
 mytest mystruct={0},myout;
 mystruct.i=5;
 strcpy(mystruct.a,"zheng");
 mystruct.d=5.06;
 
 if(WritePrivateProfileStruct("zheng","test",(mytest *)&mystruct,sizeof(mystruct),"c:\\myfile.ini"))
 {
  if(GetPrivateProfileStruct("zheng","test",(mytest *)&myout,sizeof(myout),"c:\\myfile.ini"))
   printf("%d\n%s\n%f\n",myout.i,myout.a,myout.d);
 
 
 }
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值