Using boost::property_tree

Some short examples of how to use the Boost property tree in order to read from and write to XML files.

Reading XML into a Boost property tree

Here’s how to read an example XML into the Boost property tree and traverse each of the the “item” sections within this XML, given that items may contain differing subsections:

For this XML example file “test1.xml” I use the following example XML taken from the Microsoft MSDN page:
Continue reading ‘Using boost::property_tree’ »

Getting started with Spire.XLS for .NET

E-iceblue Ltd. is a vendor of powerful components for .NET, Silverlight and WPF development. These products enable the user to easily read and write different formats of office files.

A quick an easy guide to setting up Spire.XLS for use in Visual Studio .NET projects is presented here.

For the purpose of clarity and helping the user get started as soon as possible, a simple ‘HelloWorld’ example is presented.
Continue reading ‘Getting started with Spire.XLS for .NET’ »

Using a subset of the boost libraries in Windows

For many C++ applications I very much want to use the Boost libraries, just not the whole set.

This post explains how to use the bcp tool to create a subset of the Boost libraries in order to leave out unnecessary libraries and tailor it to the needs of your project. One nice thing about bcp is that it can be run at any time so as to update your Boost dependencies as and when the need arises.
Continue reading ‘Using a subset of the boost libraries in Windows’ »

Converting a SYSTEMTIME to a std::string in C++

A short recipe outlining how to output a SYSTEMTIME value as a std::string.

The example format will be “YYYY-MM-DD HH:MM:SS.MMM”

I specifically wanted to include milliseconds.

In this example I employ three possible techniques:

1. MFC CString
2. std::ostringstream
3. sprintf
Continue reading ‘Converting a SYSTEMTIME to a std::string in C++’ »

Using boost::filesystem

Examples of using boost::filesystem for various things as and when I encounter them…

Many have been lifted from the StackOverflow site.

For reasons of brevity and clarity I generally avoid extraneous code such as exception handling etc in these examples and just focus on the techniques themselves.


1. Copying a directory

This recursively uses boost::filesystem::create_directory to create a copy of a directory including its contents, sub-directories etc.

For example the MyStuff folder:

BoostCreateDirectory1

Use the following code snippet to re-create a copy of the MyStuff folder, and rename it MyStuff2:
Continue reading ‘Using boost::filesystem’ »

Installing and using OpenSSL SHA-256 in Visual C++

Background

SHA-256 is a cryptographic hash function developed by the US. National Security Agency (NSA) as a U.S. Federal Information Processing Standard (FIPS). The SHA acronym stands for Secure Hash Algorithm. A hash function operates on an arbitrary amount of data and returns a fixed-size bit string, the cryptographic hash value.

So why would such an algorithm be useful? Its utility lies in the fact that attempts to change the original data will almost certainly change the hash value returned by the algorithm. An obvious application would be to apply such an algorithm to a file (text or binary) as a means of determining whether or not it has been tampered with.

This post shows you how to use SHA-256 as implemented by the OpenSSL open source project, and use it within Windows / Visual C++ environments to produce digital signatures of strings or files.
Continue reading ‘Installing and using OpenSSL SHA-256 in Visual C++’ »

Reading the status of DVD drives in C++

A short and to-the-point C++ recipe for determining the status of your PC / laptop DVD.

To study this area in more depth, follow this link for more information, which is where I got much of this inspiration for this code snippet. It works.

http://ws0.org/windows-how-to-get-the-tray-status-of-the-optical-drive/

Full code listing
Continue reading ‘Reading the status of DVD drives in C++’ »

Creating silent installs of audio and video codecs using K-Lite

Suppose you wish to implement a silent installation of audio and video codecs for windows. It may be that you wish to execute this as a pre-requisite for a main application you are installing, while avoiding dialog windows or command prompts from appearing while it is doing this. Hence the use of so-called ‘silent’ or ‘unattended’ installations. This post shows you how to create a silent installation of K-Lite audio/video codecs.
Continue reading ‘Creating silent installs of audio and video codecs using K-Lite’ »