Skip to content

Instantly share code, notes, and snippets.

@kjunichi
Created May 9, 2026 10:51
Show Gist options
  • Select an option

  • Save kjunichi/86e351fb3555913d1347aa5b25780c33 to your computer and use it in GitHub Desktop.

Select an option

Save kjunichi/86e351fb3555913d1347aa5b25780c33 to your computer and use it in GitHub Desktop.
import { DynamicLibrary } from 'node:ffi';
// DLLのロード
const user32 = new DynamicLibrary('user32.dll');
// 関数の定義とシンボルの取得
// MessageBoxW(HWND hWnd, LPCWSTR lpText, LPCWSTR lpCaption, UINT uType)
const MessageBoxW = user32.getFunction('MessageBoxW', {
parameters: ['pointer', 'buffer', 'buffer', 'u32'],
result: 'i32'
});
const versionText = `現在の Node.js バージョンは ${process.version} です!\0`;
// 引数の準備(ワイド文字列はBufferに変換)
const text = Buffer.from(versionText, 'utf16le');
const caption = Buffer.from('FFI Test\0', 'utf16le');
// 実行
const result = MessageBoxW(null, text, caption, 0);
console.log('Result:', result);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment