kinda reimplementation of GPL'd ThreadSpecificWin.cpp