Template based Registry class with serialization

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
It further provides the capability to serialize object structures to the registry using the objects "Serialize(CArchive& ar)" function.
(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 Kb
Download source - 3 Kb


Comments

  • Trist surrounded to be gifted to alter power unavailable to customers

    Posted by motherdhmm on 06/04/2013 09:03pm

    [url=http://blog.cheapbeatsbydre.co.nz/]beats by dre nz[/url] Beats past Dr Dre Studio Diamond Headphone Red it is most popular beats near dre studio in Australia. Fashion style and looks, to become a hoard of music lovers. Beats sooner than Dr Dre Studio Diamond Headphone Red targets music afficionados unsound to set right the look like worth of their small audio devices.Beats close to Dre Opening systems with Neodymium magnets tuned fitting for a honest logical production, you pay attention to to music more convenient. [url=http://blog.cheapbeatsbydre.co.nz/]beats by dre[/url] We recollect the Freak Radio is the head manufacturer in the world which developed the energetic Audio and Video equipments pull, the company was established by means of away Chinese American Mr. Lee Mr Noel in 1979. And this label won lots of reputations from the music lovers seeing that the modish originate and sensational quality. Fully mining market require and deepening benefit consciousness, establishing the care gonfalon, in orderliness to prevail in the affirmation from the consumers. [url=http://www.headphonescheaponlineaustralia.com/dre-beats-solo-hd-c-66_68_77.html]Dre beats solo HD[/url] Pinchbeck possibly man is tiny. These 2 documents are provided with the real stock and not with the imitation. The battery take responsibility of the authentic handle, of course, has the serial number and Dr Dre¡¯s signature.The make a pretence of doesn¡¯t be suffering with any ( Incarnation of phoney battery guard not included, just guess an unfurnished time where the signature and serial should be). The differences lie in the stuff of the discrimination cup and the aforementioned battery covers.The battery denounce for light on the real deal also seems to be a a tad brighter

    Reply
  • Nike Aura Max+instagram, wishes you hold the color to wear on your feet!

    Posted by madytreathy on 04/22/2013 01:20am

    Recollect 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.

    Reply
  • Updated version available

    Posted by Legacy on 06/26/2001 12:00am

    Originally posted by: Frank Melber

    Hi folks,
    I 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.

    Reply
  • Thank you!!!

    Posted by Legacy on 04/23/2001 12:00am

    Originally posted by: kyusun

    good source!!!
    Thank you very much~~~~*^^*

    Reply
  • Access rights should be added

    Posted by Legacy on 01/13/2000 12:00am

    Originally 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
Leave a Comment
  • Your email address will not be published. All fields are required.

Top White Papers and Webcasts

  • On-demand Event Event Date: December 18, 2014 The Internet of Things (IoT) incorporates physical devices into business processes using predictive analytics. While it relies heavily on existing Internet technologies, it differs by including physical devices, specialized protocols, physical analytics, and a unique partner network. To capture the real business value of IoT, the industry must move beyond customized projects to general patterns and platforms. Check out this webcast and join industry experts as …

  • Today's agile organizations pose operations teams with a tremendous challenge: to deploy new releases to production immediately after development and testing is completed. To ensure that applications are deployed successfully, an automatic and transparent process is required. We refer to this process as Zero Touch Deployment™. This white paper reviews two approaches to Zero Touch Deployment--a script-based solution and a release automation platform. The article discusses how each can solve the key …

Most Popular Programming Stories

More for Developers

RSS Feeds