Skip to content
This repository was archived by the owner on Dec 3, 2024. It is now read-only.
This repository was archived by the owner on Dec 3, 2024. It is now read-only.

TypeError: error setting return value - buf.writeUInt8 is not a function when call EnumWindows #1

Open
@xmsz

Description

@xmsz

code:

var user32 = new ffi.Library('user32', {
  GetWindowThreadProcessId: ['long', ['long', 'pointer']],
  EnumWindows: ['bool', ['pointer', 'long']],
});
const callback = new ffi.Callback('bool', ['long', 'int32'], (hwnd, lParam) => {
  const lpdwProcessId = ref.alloc('int');
  user32.GetWindowThreadProcessId(hwnd, lpdwProcessId);
  if (lpdwProcessId == lParam) {
    return false;
  }
  return true;
});
user32.EnumWindows(callback, 0);

result

Uncaught Error: TypeError: error setting return value - buf.writeUInt8 is not a function
    at Object.proxy [as EnumWindows] (node_modules\.pnpm\@[email protected]\node_modules\@lwahonen\ffi-napi\lib\_foreign_function.js:61:14)
    at ./src/renderer/hooks/useRecordController.tsx (useRecordController.tsx:93:8)
    at options.factory (react refresh:6:1)
    at __webpack_require__ (bootstrap:24:1)
    at fn (hot module replacement:62:1)
    at ./src/renderer/components/Aside.tsx (Add.tsx:384:20)
    at options.factory (react refresh:6:1)
    at __webpack_require__ (bootstrap:24:1)
    at fn (hot module replacement:62:1)

I saw this issuse node-ffi-napi/node-ffi-napi#225 (comment)

And i change true to 1, false to 0, it works but no real a good solution

So how can i fix it

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions