Various fixes

Sorry that it is just two big commits...

Changes released under the MIT license.
Hmm, I believe the printf's should show up in the console too, that's interesting.
In order to keep the PR small I'd suggest you add them back so the diff only shows the interesting changes.

Note that I'm not familiar with the libgdiplus code myself and not in a position to properly review this ;-)