Fixed casts to and from handles.

The only legal one is a reinterpret to a uint64 (even on 32-bit platforms).

Fixes #302