/////////////////////////////////////////////////////////////// // $Source: CMReg.cpp // $Author: Christophe Mortier // // $Description: Definitions of Class Register ,. // // $Log: // Revision 1.0 05/10/1999 Mortier /////////////////////////////////////////////////////////////// #include #include #include #include "CMReg.h" //////////////////////// // Default constructor. //////////////////////// CMReg::CMReg(void) { HKey=NULL; } ////////////////////////// // Open a key on creation /////////////////////////////////////////// // str is a pointer to the name of the key /////////////////////////////////////////// CMReg::CMReg(char *str) { HKey=NULL; Open(str); } /////////////////////// // Default Destructor. /////////////////////// CMReg::~CMReg() { Close(); } /////////////////////////////////////////////////////////// // Open the given key , if it doesn't exist it is created. //////////////////////////////////////////////////////////////// // str is a pointer to the name of the key // the function return FALSE if not opened , otherwise the result //////////////////////////////////////////////////////////////// BYTE CMReg::Open(char *str) { DWORD Disp; Close(); if(RegCreateKeyEx(HKEY_LOCAL_MACHINE,str,NULL,NULL,REG_OPTION_NON_VOLATILE , KEY_ALL_ACCESS ,NULL,&HKey,&Disp) != ERROR_SUCCESS) return FALSE; return (BYTE)Disp; } ///////////////// // Close the key ///////////////// void CMReg::Close(void) { if(HKey) { RegCloseKey(HKey); HKey=NULL; } } //////////////// // Delete a key //////////////// BYTE CMReg::Delete(char *str) { Close(); Open(str); if(RegDeleteKey(HKEY_LOCAL_MACHINE,str) != ERROR_SUCCESS) return FALSE; else return TRUE; } /////////////////////////// // Read a byte on register //////////////////////////////////////////////////////////// // val is a pointer to the name of the variable in the key //////////////////////////////////////////////////////////// BYTE CMReg::ReadByte(char *val) { BYTE data; // variable that will receive the size readed and must // contain ,before the call ,the size to read, init to 1. DWORD size=1; if(HKey) if(RegQueryValueEx(HKey,val,NULL,NULL,&data,&size)) data=0; return data; } //////////////////////////// // Write a byte on register //////////////////////////////////////////////////////////// // val is a pointer to the name of the variable in the key // data is the ... data byte to put in the key //////////////////////////////////////////////////////////// void CMReg::WriteByte(char *val, BYTE data) { // 1 because this is the number of bytes if(HKey) RegSetValueEx(HKey,val,NULL,REG_BINARY,&data,1); } /////////////////////////// // Read a word on register //////////////////////////////////////////////////////////// // val is a pointer to the name of the variable in the key //////////////////////////////////////////////////////////// WORD CMReg::ReadWord(char *val) { WORD data; // variable that will receive the size readed and must // contain before the call the size to read, init to 2. DWORD size=2; if(HKey) if(RegQueryValueEx(HKey,val,NULL,NULL,(BYTE *)&data,&size)) data=0; return data; } //////////////////////////// // Write a word on register //////////////////////////////////////////////////////////// // val is a pointer to the name of the variable in the key // data is the ... data byte to put in the key //////////////////////////////////////////////////////////// void CMReg::WriteWord(char *val, WORD data) { if(HKey) RegSetValueEx(HKey,val,NULL,REG_BINARY,(BYTE *)&data,2); } ////////////////////////////////// // Read a double word on register //////////////////////////////////////////////////////////// // val is a pointer to the name of the variable in the key //////////////////////////////////////////////////////////// DWORD CMReg::ReadDWord(char *val) { DWORD data,size=4; if(HKey) if(RegQueryValueEx(HKey,val,NULL,NULL,(BYTE *)&data,&size)) data=0; return data; } /////////////////////////////////// // Read a string from the register //////////////////////////////////////////////////////////// // val is a pointer to the name of the variable in the key // data is a pointer to the string in witch de data will be // size is the size of the string to read ////////////////////////////////////////// void CMReg::ReadString(char *val,char *data,DWORD size) { if(HKey) if(RegQueryValueEx(HKey,val,NULL,NULL,(BYTE *)data,&size)) data[0]=NULL; } //////////:////////////////// // Read raw data on register ///////////////////////////// void CMReg::ReadData(char *val,BYTE *data,DWORD size) { if(HKey) if(RegQueryValueEx(HKey,val,NULL,NULL,data,&size)) data[0]=NULL; } /////////////////////////////////// // Write a double word on register //////////////////////////////////////////////////////////// // val is a pointer to the name of the variable in the key // data is the ... data byte to put in the key //////////////////////////////////////////////////////////// void CMReg::WriteDWord(char *val, DWORD data) { if(HKey) RegSetValueEx(HKey,val,NULL,REG_BINARY,(BYTE *)&data,4); } ////////////////////////////// // Write a string on register //////////////////////////////////////////// // val = see other... // data is a pointer to the string to write //////////////////////////////////////////// void CMReg::WriteString(char *val, char *data) { if(HKey) RegSetValueEx(HKey,val,NULL,REG_SZ,(BYTE *)data,strlen(data)); } ////////////////// // Write raw data ////////////////// void CMReg::WriteData(char *val, BYTE *data,DWORD size) { if(HKey) RegSetValueEx(HKey,val,NULL,REG_BINARY,data,size); }