made private global static
fixed some cppcheck warnings: remove checks for unsigned numbers being negative, fixed some format strings %d to %u
minor cleanup: changed some 0/1 to false/true; changed some void* to HANDLE; changed some for loops to memset()
fixed a bug where a struct's fields were never set in the error path and then read anyway
Fixed type warning.