I see, because the main console app run to end immediately, while ahk msgbox running in a thread and soon destroied. If I prompt a msgbox in current process (using user32.dll here), I can see the ahk msgbox.
Code: Select all
const ffi = require('ffi-napi');
const dll_type = process.arch=='x64'?'x64w':'W32w'
const
libPath = `D:/A/ahk/AutoHotkey_H/ahkdll-v1-release-master/${dll_type}_MT/AutoHotkey.dll`;
// libPath = `D:/A/ahk/AutoHotkey_H/ahkdll-v1-release-master/${dll_type}/AutoHotkey.dll`;
function showText(text, encoding='utf8') {
return new Buffer.from(text, encoding).toString('binary');
};
const ahkdll = new ffi.Library(libPath, {
'ahkTextDll':
[
'int32',
['string','string','string']
],
});
ok = ahkdll.ahkTextDll(
showText('Msgbox I am AHK \n MouseMove, 0,0 '), showText('') ,showText('TITLE')
console.log(ok)
const fs = require('fs');
ahk_script_string = fs.readFileSync("D:/A/ahk/friends.ahk",'utf8')
ok = ahkdll.ahkTextDll(
showText(ahk_script_string,'utf16le'), showText('') ,showText('','utf16le')
);
console.log(ok)
// return
const myUser32 = new ffi.Library('user32', {
'MessageBoxW':
[
'int32',
['int32', 'string', 'string', 'int32'],
],
});
const isOk = myUser32.MessageBoxW(
0,
showText('I am user32!','ucs2'),
showText('Hello, World!','ucs2'),
1
);
// console.log(isOk);