Search code examples
javascriptfirefox-addonjsctypes

js-ctypes: Pointer to intptr_t


In ctypes I have

TBButton.ptr(ctypes.UInt64("0x1e677e60")

This is equivalent to aButton.address() in this line of code here:

var rez = SendMessage(hToolbar, 0x417 /** TB_GETBUTTON **/, 1, aButton.address());

When I run this code i get error:

Exception: expected type intptr_t, got TBButton.ptr(ctypes.UInt64("0xaa4eb20"))

So this is because in my SendMessage defintion I have this:

var SendMessage = user32.declare('SendMessageW', ctypes.winapi_abi, ctypes.intptr_t,
    ctypes.voidptr_t, // HWND
    ctypes.uint32_t, // MSG
    ctypes.uintptr_t, // WPARAM
    ctypes.intptr_t // LPARAM
);

So my question is: What is the type of TBButton.ptr(ctypes.UInt64("0x1e677e60") so I can change LPARAM in the SendMessage defintion to this type.

Or alternatively: Is it possible to make this a intptr_t? Something like ctypes.intptr_t(aButton.address()), which I tried this it doesn't work.


Solution

  • It is a pointer to TBButton, whatever TBButton is, while intptr_t is actually an integer large enough to hold a pointer address.

    You need to cast the pointer to an intptr_t.

    var lparam = ctypes.cast(tbbuttonptr, ctypes.intptr_t);