You should not be comparing the machine type with IMAGE_FILE_MACHINE_I386 to find out if it is 32 or 64 bit, you should check the Magic member of IMAGE_OPTIONAL_HEADER. The current code would fail on 32-bit ARM files and old rare stuff like Alpha and Power PC.