Make it work under Windows and Mac OS X plus some minor fixes

Hi Clément,

I've updated your code to make it compile and work under Mac OS and Windows.
Moreover I've took the liberty to fix some compiler warnings and memory leaks.

Please let me know what you think.

Best regards
Rolf