0

I need to pass ~0L to my function, how can I do this, no matter what I do ~0 is being turned to -1

This is the C code:

812   int result = GetProperty(window, property_name,
813                            (~0L), // (all of them)
814                            &type, &format, &num_items, &properties);

This is my jsctypes:

var result = GetProperty(window, property_name, ctypes.long(~0), type.address(), format.address(), num_items.address(), properties.address()

Notice the ctypes.long(~0) how to make this be the 111111111111111111111111111111 for 32bit slash the 64 1's for 64bit?

Thanks

reference topic: What does (~0L) mean?

Community
  • 1
  • 1
Noitidart
  • 35,443
  • 37
  • 154
  • 323

2 Answers2

1

declare it unsigned long, ~0UL

Andras
  • 2,995
  • 11
  • 17
  • I had to google this, but does ctypes.unsigned_long(~0) look right? Be sure to declare the matching C++ code as expecting an unsigned long too. In C++, ~0 (all bits set) is also how -1L is represented; whether it's treated as -1L or ~0UL depends on how it's declared. – Andras Dec 22 '14 at 04:40
  • Oh I thought you were a js-ctypes guy. Yeah i tried that, Im not sure its the right way to do it. Im not getting data which might have something to do with this. – Noitidart Dec 22 '14 at 04:48
  • no, I'm more of a C/C++/nodejs guy. I've written nodejs plugins. If you're not getting the data, try printing out everything you're receiving on the C side, that might help show what's happening. – Andras Dec 22 '14 at 05:02
0

Solution was to use ctypes.long(~0) this is good for 32 bit and 64 bit :) Thanks to @arai.

21:45 noida how to use ~0L in jsctypes?

22:07 arai noida: 32bit or 64bit?

22:11 noida can you show me how to do for both plz

22:17 arai noida: I guess ctypes.int32_t(~0) and ctypes.int64_t(~0) will work

22:20 noida -0x80000000

22:20 noida that wont work huh?

22:20 arai it uses ctypes.long for the parameter, so ctypes.long(~0) would be better

22:23 arai ~0L is 0xFFFFFFFFFFFFFFFF, right?

22:24 noida i thought it was: 0x7ffffff

22:29 arai printf("%lx\n", ~0L); outputs "ffffffffffffffff"

22:31 arai it would be more better to use ctypes.long(~0) for consistency

22:33 noida also using the long method will be cross 64/32 bit right?

22:37 arai "This automatically converts to an Int64 JavaScript object on all platforms, since it's unknown whether this is a 32-bit or 64-bit value. This is done for compatibility's sake."

22:37 arai https://developer.mozilla.org/en-US/docs/Mozilla/js-ctypes/js-ctypes_reference/ctypes

Community
  • 1
  • 1
Noitidart
  • 35,443
  • 37
  • 154
  • 323