Add ThrowCError to throw an exception on C library errors.
Fix MSVC build.