Move calls to Win32 API calls outside of locked sections.