Updates to get code building on MSVC

MSVC seems to be MUCH more touchy about the types of functions being passed around. This means that some of our code has more casting.

I've created a new function `CastNullAdapter` that cleans up that usage.

The down side is lots of little code changes. The upside is that some of the existing code is now more clean.