Fix invalid cast on Windows