Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Build issues but working in as package. #226

Open
Universal-Invariant opened this issue Mar 11, 2025 · 0 comments
Open

Build issues but working in as package. #226

Universal-Invariant opened this issue Mar 11, 2025 · 0 comments

Comments

@Universal-Invariant
Copy link

I'd like to outline what I did to get this to work since ffi-napi was crashing on import. I tried to follow the build instructions(I'm pretty new at this) but there are some missing issues. Specifically npm i koffi gave an error about it missing in the registry: [I spend a lot of time on ffi-napi trying to setup some generate binding generators only to find out it wouldn't work ;/ I should have tried something simpler.

  1. Try installing using npm:

Specifically, but note that I tried various versions and the dev was my build,
npm install koffi
npm ERR! code E404
npm ERR! 404 Not Found - GET https://registry.npmjs.org/@types%2fkoffi - Not found
npm ERR! 404
npm ERR! 404 '@types/koffi@^3.0.0-dev' is not in this registry.
npm ERR! 404
npm ERR! 404 Note that you can also install from a
npm ERR! 404 tarball, folder, http url, or git url.

  1. Clone the rygel sources, follow the instructions given by koffi:
    cd src/koffi
    node ../cnoke/cnoke.js

passed

cd src/koffi/test
node ../../cnoke/cnoke.js

node test.js

Fail because "require" is missing. Maybe there is more to it

  1. To get it to work in my package since step 1 fails. To do this use npm link while in src/koffi then use npm link koffi in the app dir. It should put koffi in the types dir and it should be accessible using const koffi = require('koffi');

  2. I used the following code to test and it worked.

const koffi = require('koffi');

// Load the shared library
const lib = koffi.load('user32.dll');

// Declare constants
const MB_OK = 0x0;
const MB_YESNO = 0x4;
const MB_ICONQUESTION = 0x20;
const MB_ICONINFORMATION = 0x40;
const IDOK = 1;
const IDYES = 6;
const IDNO = 7;

// Find functions
const MessageBoxA = lib.func('__stdcall', 'MessageBoxA', 'int', ['void *', 'str', 'str', 'uint']);
const MessageBoxW = lib.func('__stdcall', 'MessageBoxW', 'int', ['void *', 'str16', 'str16', 'uint']);

let ret = MessageBoxA(null, 'Do you want another message box?', 'Koffi', MB_YESNO | MB_ICONQUESTION);

if (ret == IDYES)
MessageBoxW(null, 'Hello World!', 'Koffi', MB_ICONINFORMATION);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant