Fix compilation errors and warnings in MSVC