Template based Registry class with serialization
Posted
by Frank Melber
on January 5th, 2000
It was inspired by the registry API wrapper class by Shane Martin which you can find here at codeguru.
Environment: VC6 SP3, NT4 SP5
I first used the registry class provided by Shane. But - for my purposes - I needed other functionality. So I wrote my own code.
This class now provides the capability of reading and writing any kind of object which supports archive operation (template based).
Some of these are:
- BYTE
- WORD
- int
- LONG
- DWORD
- float
- double
- SIZE and CSize
- CString
- POINT and CPoint
- RECT and CRect
- CTime and CTimeSpan
(Be sure that these structures are smaller than 2048 bytes - otherwise an *.ini file or something would be better.)
Another feature is that you can save and resore the settings of the application window(s) by simply passing a pointer to the "Read" or "Write" Function.
Usage is very simple...
CRegistry reg;
CString sRegPath("YourApp\\Path\\Settings");
CString sString("I am a String");
CString sStringBin("I am a binary String");
int nValue = -1234567890;
double dValue = -1234567890.1234;
DWORD dwValue = 1234567890;
DWORD dwValueBin = 1234567890;
CRect rcWnd;
CYourObject object;
// Fill the rcWnd...
GetWindowRect(rcWnd);
// Check the key...
if (!reg.VerifyKey(HKEY_CURRENT_USER, sRegPath))
reg.CreateKey(HKEY_CURRENT_USER, sRegPath);
// Open...
reg.Open(HKEY_CURRENT_USER, strRegPath);
// Writing/Reading as "String"...
reg.WriteString("CString", sString);
reg.ReadString("CString", sString);
// Writing/Reading String as "binary" (template function)...
reg.WriteType("CStringBin", sStringBin);
reg.ReadType("CStringBin", sStringBin);
// Writing/Reading int as "binary" (template function)...
reg.WriteType("int", nValue);
reg.ReadType("int", nValue);
// Writing/Reading double as "binary" (template function)...
reg.WriteType("double", dValue);
reg.ReadType("double", dValue);
// Writing/Reading DWORD...
reg.WriteDWORD("DWORD", dwValue);
reg.ReadDWORD("DWORD", dwValue);
// Writing/Reading DWORD as "binary" (template function)...
reg.WriteType("DWORDBin", dwValueBin);
reg.ReadType("DWORDBin", dwValueBin);
// Writing/Reading CRect as "binary" (template function)...
reg.WriteType("CRect", rcWnd);
reg.ReadType("CRect", rcWnd);
// Writing/Reading Window (WINDOWPLACEMENT)...
reg.Write("Wnd", this);
reg.Read("Wnd", this);
// Writing/Reading CObject...
reg.Write("Object", object);
reg.Read("Object", object);
// Not necessary (object is automatically closed at destruction)
reg.Close();
For further explanation look at the sample application.
If you have any questions or some ideas how to improve this, bugs, errors, etc. feel free to send me a mail.
Downloads
Download demo project - 24 KbDownload source - 3 Kb

Comments
Nike Aura Max+instagram, wishes you hold the color to wear on your feet!
Posted by madytreathy on 04/22/2013 01:20amRecollect in 2008, if not earlier, when Nike launched on of the independent shoe color projects, the catchword "Bound Your Colours", "Nike PhotoiD" scheme, [url=http://markwarren.org.uk/goodbuy.cfm]nike free run[/url] reply has not been as hearty as expected. Deem, 2008 Canon IXUS 80 IS Digital greetings card arcade but one 8 million pixels, Nokia, the mobile phone retail is the at worst leadership, NikeiD was advocate to color in the photos as a infrastructure quest of sneakers excise color, although interesting, but does trouble some. Instagram which cause this item hold up to ridicule and simple, Nike PHOTOiD homeopathic upgrade customization services, recently [url=http://markwarren.org.uk/property-waet.cfm]air max 90 uk[/url] released a strange plan. That such iD can you utensil pictures as instagram account shoe color, the meanwhile offer Nike Air Max shoes and Nike Puff Max 1, Nike Air Max 90 953 options. Interested in children's shoes, you [url=http://markwarren.org.uk/goodbuy.cfm]nike free run uk[/url] can without exception conform with each other's legitimate website photoid.Nike.com, in reckoning to skim through other people's artistic work, or you can struggle to upload your own instagram photo, build your own Nike Mood Max.
ReplyUpdated version available
Posted by Legacy on 06/26/2001 12:00amOriginally posted by: Frank Melber
Hi folks,
ReplyI have an updated version which features read/write raw data and implements optional encryption using the CryptoAPI. Further on access rights are added ;-).
Send me an email if you're interested in it.
Thank you!!!
Posted by Legacy on 04/23/2001 12:00amOriginally posted by: kyusun
good source!!!
ReplyThank you very much~~~~*^^*
Access rights should be added
Posted by Legacy on 01/13/2000 12:00amOriginally posted by: Stefan Migowsky
Hi,
access rights should be added as a default parameter to
all the functions, instead of assumming KEY_ALL_ACCESS.
This will cause an error if the owner of the process does
not have admin rights on NT and wants to read initial values
from HKEY_LOCAL_MACHINE.
Stefan
Reply