Unrelated, but it looks liek QUERYINTERFACE is overused in here.  These should probably be static casts - the the result isn't checked for being NULL anyway.