js-ctypes: Pointer to intptr_t

js-ctypes: Pointer to intptr_t

本文关键字:intptr to Pointer js-ctypes      更新时间:2023-09-26

在ctypes中我有

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

这相当于这行代码中的aButton.address():

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

当我运行这段代码时,我得到错误:

异常:期望类型intptr_t,得到TBButton.ptr(ctypes.UInt64("0xaa4eb20"))

这是因为在我的SendMessage定义中我有这个:

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
);

所以我的问题是:TBButton.ptr(ctypes.UInt64("0x1e677e60")的类型是什么,以便我可以将SendMessage定义中的LPARAM更改为这种类型。

或者:是否有可能使其成为intptr_t ?像ctypes.intptr_t(aButton.address())这样的东西,我试过了,它不起作用。

这是一个指向TBButton的指针,不管TBButton是什么,而intptr_t实际上是一个大到足以容纳指针地址的整数。

您需要将指针强制转换为intptr_t

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