使用文本注册表INI文件

 

1:“注册表”类是CRegisterDOS版本不支持多线程中的同步WINDOWS版本支持多线程中的同步 ;本接口能够将在键值后面的注释,在修改后仍能正确的写回。

2主要接口如下所示

     FILE*  GetFile(){return(m_pFile);}; //判断文件是否装载成功

     static int      Atoi(char *pStr);//计算16进制值

     static int      GetCount(char *pStr,char nCh);//计算中的某一字符的出现频率

     static char*  GetString(int nIndex,char nCh,char *pStrSource);//从串中得到以某字符分隔的串

     static char*    TrimLeft(char  *pStr);//中的左空格删去

     static char*  TrimRight(char *pStr); //中的右空格删去

     static BOOL     IsProfileBoolen(char *pStr); //判断是否表达真

    //读键值

     char*    GetProfileString(char *pStrSegment,char *pStrKey,char *pStrDefault="");

     long     GetProfileLong(char *pStrSegment,char *pStrKey,long lDefault=0L);

     WORD    GetProfileWord(char *pStrSegment,char *pStrKey,WORD wDefault);

     int     GetProfileInt(char *pStrSegment,char *pStrKey, int  nDefault);

     float   GetProfileFloat(char *pStrSegment,char *pStrKey,float fDefault);

     double  GetProfileDouble(char *pStrSegment,char *pStrKey,double dbDefault);

     //写键值

     BOOL    WriteProfileString(char *pStrSegment,char *pStrKey,char *pStrDefault);

     BOOL    WriteProfileLong(char *pStrSegment,char *pStrKey,long lDefault);

     BOOL    WriteProfileWord(char *pStrSegment,char *pStrKey,WORD wDefault);

     BOOL    WriteProfileInt(char *pStrSegment,char *pStrKey, int  nDefault);

     BOOL    WriteProfileFloat(char *pStrSegment,char *pStrKey,float fDefault);

     BOOL    WriteProfileDouble(char *pStrSegment,char *pStrKey,double dbDefault);

3:使用举例

#include “Symbol.h”

#include “Register.h”

BOOL MySample_27()

{

CRegister* pRegister = new CRegister("Config.SYS");

if (pRegister == NULL || NULL == pRegister->GetFile())

{

    DELETE(pRegister);

    return(FALSE);

}

//读一整数

int nHello = pRegister->GetProfileInt(” Boot”, “Hello”, 37);

//读一无符号整数

int nSign = pRegister->GetProfileInt(” Boot”, “Sign”, 37u);

//读一长整数

long lgGood = pRegister->GetProfileLong(” Boot”, “Good”, 37L);

//读单精度浮点数

float fData = pRegister->GetProfileFloat(” Boot”, ”LiPing”, 0.5f);

//读双精度浮点数

double dbData = pRegister->GetProfileDouble(” Boot”, ”Line4”, 3.7);

//读布尔变量

BOOL bBoolV = pRegister->IsProfileBoolen(pRegister->GetProfileString(“Boot”,”BootV”,”True”));

//读字符串

char strPrintName[256];

_fstrcpy(strPrintName, pRegister->GetProfileString(” Boot”, “Print”, “LPT1”));

 

//写一整数

pRegister->WriteProfileInt(” Boot”, “Hello”, nHello);

//写一无符号整数

pRegister->WriteProfileInt(” Boot”, “Sign”, nSign);

//写一长整数

pRegister->WriteProfileLong(” Boot”, “Good”, lgGood);

//写单精度浮点数

pRegister->WriteProfileFloat(” Boot”, ”LiPing”, fData);

//写双精度浮点数

pRegister->WriteProfileDouble(” Boot”, ”Line4”, dbData);

//写布尔变量

pRegister->WriteProfileString(“Boot”,”BootV”,((bBoolV)?”True”:”False”));

//写字符串

pRegister->WriteProfileString(” Boot”, “Print”, strPrintName);

 

delete pRegister;

}