You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
57 lines
1.8 KiB
C
57 lines
1.8 KiB
C
/*----------------------------------------------------------
|
|
平台无关的INI文件读写函数 V1.65
|
|
|
|
张磊 2002.10.3
|
|
----------------------------------------------------------*/
|
|
|
|
#ifndef INI_FILE_H
|
|
#define INI_FILE_H
|
|
|
|
#include "platform_def.h"
|
|
|
|
#define MAX_LINE_BUF_LENGTH 2048 //最大行缓冲区长度
|
|
|
|
#define FILE_OPEN_ERROR -1 //文件打开错误
|
|
#define SECTION_NOT_FOUND -2 //段没有找到
|
|
#define KEY_NOT_FOUND -3 //键没有找到
|
|
|
|
//工具函数
|
|
void StrTrimLeft(char* szBuf);
|
|
void StrTrimRight(char* szBuf);
|
|
void StrTrimAll(char* szBuf);
|
|
long GetFileSize(char* lpszFileName);
|
|
int ReadLineFromFile(FILE* IniFile, char* lpszLineBuf, int iLen); //从指定文件中读取一行内容
|
|
bool IfBeforeHasRet(FILE* pFile); //辅助函数,判断当前文件位置前面是否是换行符号
|
|
|
|
//读配置文件中指定段下指定键的值(字符串)
|
|
int QGetPrivateProfileString(
|
|
char* lpszSectionName, //段名
|
|
char* lpszKeyName, //键名
|
|
char* lpszDefault, //缺省字符串
|
|
char* lpszReturnedString, //结果字符串
|
|
u_32 nSize, //结果字符串长度
|
|
char* lpszFileName, //ini文件名
|
|
char* lpszRemarkInLineStr = (char*)";", //行内注释符
|
|
char chContinueLineChar = '\\' //续行符号
|
|
);
|
|
|
|
//读配置文件中指定段下指定键的值(整数)
|
|
int QGetPrivateProfileInt(
|
|
char* lpszSectionName, //段名
|
|
char* lpszKeyName, //键名
|
|
int nDefault, //缺省值
|
|
char* lpszFileName, //ini文件名
|
|
char* lpszRemarkInLineStr = (char*)";", //行内注释符
|
|
char chContinueLineChar = '\\' //续行符号
|
|
);
|
|
|
|
//向配置文件写入指定段下指定键的值(字符串)
|
|
int QWritePrivateProfileString(
|
|
char* lpszSectionName, //段名
|
|
char* lpszKeyName, //键名
|
|
char* lpszString, //要写入的字符串
|
|
char* lpszFileName //INI文件名
|
|
);
|
|
|
|
#endif
|