Added try/catch blocks around all winapi calls