zhangyuang / node-ffi-rs

Implement ffi in Node.js by Rust and NAPI
MIT License
189 stars 7 forks source link

expect External, got: Object #73

Closed tanhh326 closed 2 months ago

tanhh326 commented 2 months ago

Current ffi-rs version

1.0.91

Current Node.js arch

18.20.4

$ node -e "console.log(process.arch, process.platform)"

Descibe your problem in detail

const winEventProcess = createPointer({
    paramsType: [funcConstructor({
        paramsType: [
            DataType.I32, DataType.I32, DataType.I32, DataType.I32, DataType.I32, DataType.I32, DataType.I32
        ],
        retType: DataType.Void
    })],
    paramsValue: [processCallback],
})
const winEventHookRes = load({
    library: 'user32',
    funcName: 'SetWinEventHook',
    runInNewThread: true,
    paramsType: [DataType.I32, DataType.I32, DataType.I32, DataType.External, DataType.I32, DataType.I32, DataType.I32],
    retType: DataType.I32,
    paramsValue: [32779, 32779, 0, unwrapPointer(winEventProcess), 0, 0, 0],
    errno: true
})

What's your expect result

报错:Error: expect External, got: Object 改成unwrapPointer(winEventProcess)[0]

The reproduction repo address

zhangyuang commented 2 months ago

类型问题自行对照ts提示排查或参考test.ts

发自我的iPhone

------------------ Original ------------------ From: Abstract @.> Date: Wed, Sep 11, 2024 8:37 PM To: zhangyuang/node-ffi-rs @.> Cc: Subscribed @.***> Subject: Re: [zhangyuang/node-ffi-rs] expect External, got: Object (Issue #73)

Current ffi-rs version

1.0.91

Current Node.js arch

18.20.4

$ node -e "console.log(process.arch, process.platform)"

Descibe your problem in detail const winEventProcess = createPointer({ paramsType: [funcConstructor({ paramsType: [ DataType.I32, DataType.I32, DataType.I32, DataType.I32, DataType.I32, DataType.I32, DataType.I32 ], retType: DataType.Void })], paramsValue: [processCallback], }) const winEventHookRes = load({ library: 'user32', funcName: 'SetWinEventHook', runInNewThread: true, paramsType: [DataType.I32, DataType.I32, DataType.I32, DataType.External, DataType.I32, DataType.I32, DataType.I32], retType: DataType.I32, paramsValue: [32779, 32779, 0, unwrapPointer(winEventProcess), 0, 0, 0], errno: true })

What's your expect result

报错:Error: expect External, got: Object 当我改成unwrapPointer(winEventProcess)[0]也报这个错,但是程序正常运行了

The reproduction repo address

— Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you are subscribed to this thread.Message ID: @.***>

tanhh326 commented 2 months ago

@zhangyuang image 我是对照这个示例写的,大佬

zhangyuang commented 2 months ago

使用 unwrapPointer(winEventProcess)[0]