1. Avoid ALLR memory allocation routine (use new / delete).
2. Use common (TypedHandle) class to control consistency of handles.
3. Make ctors and dtors work - in most cases more work is needed to make them meaningful.
placed some variables in context
fixed some function signatures
closed a few possible buffer overruns
sorry to the platform maintainers, I can't verify what I did for non-Win32 builds