Projective and hereditary modules over rings of generalized matrices