Here are a few changes to make 64-bit build possible. The changes are mainly to use windows api in the correct way that works for both 32-bit and 64-bit builds.