WINAPI logic + warnings fix

fix signed/unsigned warnings + logic errors in WINAPI mode