Created
May 9, 2026 10:51
-
-
Save kjunichi/86e351fb3555913d1347aa5b25780c33 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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