javascript/nodejs call ahkTextDll but can not show msgbox dialog

Post AHK_H specific scripts & libraries and discuss the usage and development of HotKeyIt's fork/branch
xiecao
Posts: 4
Joined: 30 Apr 2021, 07:38

javascript/nodejs call ahkTextDll but can not show msgbox dialog

Post by xiecao » 02 May 2021, 19:38

I can get mose moving, but i can not see msgbox dialog. why?

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) {
  return new Buffer.from(text, 'ucs2').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)

xiecao
Posts: 4
Joined: 30 Apr 2021, 07:38

Re: javascript/nodejs call ahkTextDll but can not show msgbox dialog

Post by xiecao » 03 May 2021, 23:26

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);

Post Reply

Return to “AutoHotkey_H”