On the Dyon partition function in N=4 string theories