Added handle invalidate and is valid defines

Added macros to invalidate a handle and check if a handle is valid.