Click here to Skip to main content
15,868,016 members
Articles / Desktop Programming / MFC
Article

CRegisterEx - a registry wrapper class

Rate me:
Please Sign up or sign in to vote.
2.71/5 (3 votes)
5 Feb 20021 min read 51.3K   825   9   3
An easy to use all-in-one registry class

Introduction

Always wanted a class that makes it easy to use the register? Well, I hope that you found it, right here! The class has some methods that you can use within your program. It's an easy to use class, and I hope you'll like it. 

The class was made using VC++.NET beta 2, but it should be compatible with VC++ 5 and 6.

The class is called CRegisterEx, guess why :)

How is this different to other Registry classes?

Many of the registry wrappers around don't have the functionality to save POINT and RECT structures. Thereby, most of them use RegSetValue instead of RegSetValueEx. The same goes for the Query.

This wrapper is really easy to use, and allows modification. I didn't include things that already were around, but if people like it, I will do it. So this class is an attempt to make an easy to use all-in-one Registry wrapper.

Explanation

Construction is done with:

CRegisterEx (CString path);

where path stands for the rootpath. You must construct on the Heap, if you construct it on the Stack, memory leaks will occur!

The first two methods I'm going to explain are:

void WriteString(CString str, CString subPath, CString Key);
CString ReadString(CString subPath, CString Key);

With WriteString you can write a string to the register. This you must do by at least including a CString. subPath, which is used to generate a tree beneath the rootpath, and the Key attributes don't have to be included. Remember that the Key attribute will be set to "Standard".

With ReadString you can read a string from the register.

All other methods are based on these two methods. These are:

void WriteInteger(int i, CString subPath, CString Key);
int ReadInteger(CString subPath, CString Key);
void WritePoint(CPoint pt, CString subPath, CString Key);
CPoint ReadPoint(CString subPath, CString Key);
void WriteRect(CRect rect, CString subPath, CString Key);
CRect ReadRect(CString subPath, CString Key);
void WriteDouble(double dbl, CString subPath, CString Key);
double ReadDouble(CString subPath, CString Key);

As you can see, plenty of methods to use with your program.

If you've got something more to add, please use the forum field below.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


Written By
Web Developer
Netherlands Netherlands
I'm a developer in C++, however, I developed a lot in VB, Delphi and JAVA. Also I make web based applications using languages as PHP, ASP (JavaScript, VBScript), ASP.NET (C# and VB), JSP and Perl

Currently working in a small IT company.

Comments and Discussions

 
GeneralExcellent example on how it shouldn't be done. Pin
jfernb27-May-04 10:57
sussjfernb27-May-04 10:57 
GeneralRe: Excellent example on how it shouldn't be done. Pin
S van Leent27-May-04 12:16
S van Leent27-May-04 12:16 
GeneralYou have done well. Pin
magic world11-Jul-03 0:03
magic world11-Jul-03 0:03 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.