This is basically just a copy of DpiTest, but it seems like this stuff would be useful to have in sample code.