How to expose C# async methods in WinRT components

When authoring Windows Runtime (WinRT) components with C# you cannot use the standard C# async Task pattern. Say for example you have code like: public sealed class MyComponent { public async Task<string> SaveToFile(StorageFolder folder, string fileName) { var file = await folder.CreateFileAsync(fileName); var output = MakeRandomString(128); await FileIO.WriteTextAsync(file, output); return output; } } Visual Studio…… Continue reading How to expose C# async methods in WinRT components

Redirecting standard output to console in Windows

When I first started making Windows programs in the early 2000s I needed a way to display logging information visually to the user. With some internet sleuthing I discovered how to create a windows console and using black magic, how to redirect the standard input/output streams to print to this window. With that problem solved…… Continue reading Redirecting standard output to console in Windows

Getting rid of C#’s obj folders

A small tip for developers who are irritated with Visual Studio doing this to your pristine source tree: To get the obj directories out of your source tree, and somewhere nicer (your project’s build output directory for example) open up your project’s .csproj file in an external editor. Locate any line that has the <OutputPath>…… Continue reading Getting rid of C#’s obj folders

Printing Generic C++ Containers

Always wanted a simple utility function to print our an arbitrary STL container? Well, so long as your container type support directional iterators… this method I wrote will work perfectly! Its a great example for why templates are awesome #include <sstream> template<typename T> std::string dumpContainer( const T& container, std::string sep ) { typename T::const_iterator itr;…… Continue reading Printing Generic C++ Containers

Compiling Qt with Visual Studio

So your awesome project that you’re developing with Visual Studio, and you want to use Trolltech’s Qt library? Luckily Trolltech provides an awesome Visual Studio plugin that does almost everything Qt creator does (minus Intellisense support for slots). The bad news is that Trolltech doesn’t directly tell you how to go about doing this: Download…… Continue reading Compiling Qt with Visual Studio

C++ Template Name Madness

STL vectors can act as typical c-style arrays. To cast from vector<T> to T*, simply take the address of the first element. void myFunction( int* i ) { std::cout << *i << std::endl; }   // Now to pass the vector to the random function from above… std::vector myVector; myFunction( &myVector[0] );