Fix uses of ulong where 32-bit integers are expected

long/ulong can either be 32-bit or 64-bit wide.