win: fix potential HANDLE corruption due to incorrect cast

Closes #738.