Monthly Archives: January 2013

How to Set Up POCO C++ Libraries with Visual Studio 2010

I decided I would road-test the C++ framework “POCO” to see if it is worthwhile.
Setting up was a bit of a mission and took me around 2.5 hours to achieve. Here’s how I went about it:

  1. navigate to the POCO downloads page and download the basic edition sources for Windows
  2. extract it to a folder. For me, it was D:\poco-1.4.6 (“the POCO base directory”)
  3. open a Visual Studio Command Window from the Visual Studio Tools folder in your start menu.
  4. change directories to the POCO base directory and run the buildwin.cmd, passing in the relevant version of Visual Studio. For me, it was buildwin.cmd 100
  5. go make a cup of tea and watch some Youtube for 20 minutes or so
  6. once built, a directory called bin will appear in the POCO base directory. You need to add that directory to the System Environmental Path. If you do not know how to do that, Google it. It’s very easy and many people will blog about how its done. There, I just Googled it for you.
  7. create a new Visual Studio project. I went with a Win32 variety console app.
  8. right-click on the Project node in Solution Explorer and click Properties on the context menu.
  9. in the tree on the left, click on the node >C/C++
  10. in the panel that is loaded on the right, Click the Additional Include Directories TextBox, and using the wizard that launches, add a path to the directory “D:\poco-1.4.6\Foundation\include”. Add any other library you intend to use as well.
  11. in the tree on the left, click on the node >Linker
  12. in the panel that is loaded on the right, Click the Additional Include Directories TextBox, and using the wizard that launches, add a path to the directory “D:\poco-1.4.6\lib”
  13. That’s all the plumbing you need to do. Now, here is a Hello World! to show you how to incorporate it into the Console app:

    #include "stdafx.h"
    #include <Poco/String.h>
    
    using Poco::trim;
    
    int _tmain(int argc, _TCHAR* argv[])
    {
    	std::string hello("            Hello, world!          ");
    	std::string s1(trim(hello)); // "Hello, world!"
    	
    	std::cout << s1;
    
    	return 0;
    }
    

I hope this saves someone some time getting up and running with POCO.

Bus Antics

I have been playing around with the animation framework in jQuery and thought I would use it to tell a story about what happened on a bus one day.
It all happened like this:

  1. I got on the bus one day and sat next to a very big guy. I could not fit properly on my side of the seat and my leg was off the side, preventing people from comfortably walking past me.
  2. At the next stop, a guy who had a double-seat to himself got off;
  3. Then, a lady who was already sitting comfortably next to a thin guy moved to take over the whole double-seat (she clearly felt that sharing a seat with someone was beneath her :));
  4. I, however, did not mind at all and moved to sit next to the thin guy;
  5. Then, much to my amusement, a guy got on the bus and sat next to the lady, putting her in no better position than she started;

This amused me, so I thought I’d re-create the scene using jQuery (below).

Click the “Dave, Show Me What Happened” button (press F11 to go full screen):

The code which is the engine for my little melodrama is:

var undef = 'undefined'; // saves us from creating and throwing away a string every time.

if(typeof(busNamespace) === undef) {
	var busNamespace = { };
}

if(typeof(constants) === undef) {
	var constants = { };
}
		
$(function() {

	var revealStoryButton = $("#reveal");

	$("#story").hide();
	
	revealStoryButton.text(constants.readMore);
	
	revealStoryButton.click(function() {	
		var thisButton = $(this);
	
		$("#story").slideToggle(400, function(){
			if(thisButton.text() === constants.readMore) {
				thisButton.text(constants.hideStory);
			}
			else{
				thisButton.text(constants.readMore)
			}
		});		
	});

	busNamespace.bus = $('#bus');
	busNamespace.dave = $('<img id="dave" src="' + constants.urlOfPersonImage + '" />');
	busNamespace.lady = $('<img id="lady" src="' + constants.urlOfPersonImage +  '" />');
	busNamespace.someGuyWhoGotOff = $('<img id="someGuyWhoGotOff" src="' + constants.urlOfPersonImage + '" />');			
	busNamespace.newGuyGetsOn = $('<img id="newGuyGetsOn" src="' + constants.urlOfPersonImage + '" />');	
	
	busNamespace.bus.prepend(busNamespace.someGuyWhoGotOff);
	busNamespace.bus.prepend(busNamespace.dave);
	busNamespace.bus.prepend(busNamespace.lady);			
	busNamespace.newGuyGetsOn.hide();
	busNamespace.bus.append(busNamespace.newGuyGetsOn);
	
	busNamespace.daveOriginalPosition = { left: busNamespace.dave.css('left'), top: busNamespace.dave.css('top') };
	busNamespace.ladyOriginalPosition = { left: busNamespace.lady.css('left'), top: busNamespace.lady.css('top') };
	busNamespace.someGuyWhoGotOffOriginalPosition = { left: busNamespace.someGuyWhoGotOff.css('left'), top: busNamespace.someGuyWhoGotOff.css('top') };
	busNamespace.newGuyGetsOnOriginalPosition = { left: busNamespace.newGuyGetsOn.css('left'), top: busNamespace.newGuyGetsOn.css('top') };
	
	$('#onWithTheShow').on('click', busNamespace.someGuyWhoGotOffGetsOff);	
	$('#reset').on('click', busNamespace.resetPlayers);
});

(function(ns) {

	var bus;
	var dave;
	var lady;
	var someGuyWhoGotOff;
	var newGuyGetsOn;
	var daveOriginalPosition;
	var ladyOriginalPosition;
	var someGuyWhoGotOffOriginalPosition;
	var newGuyGetsOnOriginalPosition;
	
	ns.someGuyWhoGotOffGetsOff = function() {
		ns.someGuyWhoGotOff.animate({left: "+=120"}, 1000)
						.animate({top: "-=125"}, 1000)
						.animate({left: "-=120", opacity: 0}, 1000, ns.ladyAndDaveMove);							
	};
	
	ns.ladyAndDaveMove = function() {
		ns.dave.animate({left: "-=90"}, 1000)
			.animate({top: "-=70"}, 1000);
		ns.lady.animate({left: "-=150"}, 1000)
			.animate({top: "+=150"}, 1000, ns.ladyAndDaveMoveAgain);
	};
	
	ns.ladyAndDaveMoveAgain = function() {
		ns.dave.animate({top: "-=300"}, 1000)
			.animate({left: "+=90"}, 1000);
		ns.lady.animate({top: "+=98"}, 1000)
			.animate({left: "-=140"}, 1000, ns.newGuyGetsOnAndSitsNextToLady);		
	};
	
	ns.newGuyGetsOnAndSitsNextToLady = function() {
		ns.newGuyGetsOn.fadeIn(1000);
		ns.newGuyGetsOn.animate({left: "+=150"}, 1000)
					.animate({top: "+=128"}, 1000)
					.animate({left: "-=92"}, 1000);
	};
	
	ns.resetPlayers = function() {
		ns.dave.fadeOut(600, function(){
			ns.dave.hide();
			ns.dave.css({ 'left' : ns.daveOriginalPosition.left, 'top': ns.daveOriginalPosition.top });
			ns.dave.fadeIn(600);
		});		
		
		ns.lady.fadeOut(600, function(){
			ns.lady.hide();
			ns.lady.css({ 'left' : ns.ladyOriginalPosition.left, 'top': ns.ladyOriginalPosition.top });
			ns.lady.fadeIn(600);	
		});
				
		ns.someGuyWhoGotOff.css({ 
				'left' : ns.someGuyWhoGotOffOriginalPosition.left, 
				'top': ns.someGuyWhoGotOffOriginalPosition.top
			}).animate({opacity: 1}, 2000);
		
		
		ns.newGuyGetsOn.css({ 
				'left' : ns.newGuyGetsOnOriginalPosition.left, 
				'top': ns.newGuyGetsOnOriginalPosition.top
			}).hide(600);
				
	};
	
})(busNamespace);

(function(ns) {
	ns.hideStory = 'Click here to hide story';
	ns.readMore = 'Click here to read more...';	
	ns.urlOfPersonImage = "https://davidrogers.id.au/wp_jsPosts/person.png";
})(constants);

Even when having fun, I try to follow best practices, such as the use of namespaces. First code for 2013!!!

2012 Retrospective for Great Free Libs

Today, I want to do a review of the open source programming tools which I used this year and which were extremely helpful to me in getting my job done. Some of these tools shaved large amounts of time off my development work. And they helped me deliver a high quality product. This has resulted in a happy client which received robust apps at a reasonable price.

Alex FTPS Client

This is a really good library for FTP operations. I had to incorporate some FTP functionality in an application which was invoked by a scheduled task to transfer some files in a particular directory to an external partner. This library made this experience effortless. And it provides a really nice callback which allows you to write the progress of the transfer to an output (a log file in my case).

DotNetZip

An easy to use library providing zip/unzip functionality. I know what you’re thinking; the .NET framework provides that. This library makes it easier. And it makes working with directory heirarchies easy as well.

StructureMap

A great dependancy injection library. Very powerful and easy to use. And surprisingly quite light-weight. If I’m not already using the Enterprise Library, I ditch Unity for this great library.

GnuGP for Windows

See my article on Code Project to read about this great encryption library.

NLog

NLog is just great. So much functionality. So configurable. Again, if I’m not already using Enterprise Library, I use this for my logging.

MVVM Light Toolkit

This is a truly great library. It gives you just enough to implement the MVVM pattern in your XAML projects (hence the “light” in its name). I’ve used this with great success in two small applications for a client’s larger system. Quick to learn, intuitive and effective.

Task Scheduler Managed Wrapper

A full-featured library which enables you to create new Scheduled Tasks in code. Whilst I haven’t explored every nook and cranny of this library, it seems to cover almost every aspect which you could configure in Windows’ built in Task Scheduler GUI.

Here’s to finding more brilliant projects in 2013!