Replaced CriticalSection with spin locks. I couldn't find out how to lock InitializeCriticalSection()/DeleteCriticalSection().
Avoid using CRT's memory functions to reduce the footprint.
Added some missing statics.
Replaced LocalAlloc with HeapAlloc.