Search code examples
javascriptfirefox-addonjsctypes

Unwrap a UInt64 that is wrapped in a voidptr_t


In js-ctypes I have received a Windows handle (voidptr_t). In some cases a handle is null, so it is returned to me as

var ret = ctypes.voidptr_t(ctypes.UInt64('0x0'))

I want to unwrap the voidptr_t and then do ctypes.UInt64.compare(ret, ctypes.UInt64('0x0')).

Right now I'm doing this funky thing:

if (local_hwnd.toString().indexOf('UInt64("0x0")') > -1) {
    console.log('has no handle it is 0 local_hwnd.toString() = ', local_hwnd.toString());
}

Solution

  • For simple null comparisons:

    ptr.isNull()
    

    For actually unwrapping stuff (to UInt64):

    ctypes.cast(ptr, ctypes.uintptr_t).value