0

I am confused。 When using FFI-NAPI - Dll 。 The return value does not receive anything。 But print out the content (stdut) at the terminal。 I will post part of the code below and keep trying. I guess it will work after using FF-callback, but I'm not sure. Could you please take a look at it for me 。

Here is my code:


import {  myDll } from './utils/DllImport'
....
....
ipcMain.on('GetAdbProp', () => {
  var nameBuffer = Buffer.alloc(10240);
  nameBuffer.fill(0);
  nameBuffer.write('', 0, "ascii");
  const res=myDll.GetAdbProp('factory.board', nameBuffer)
  console.log(res,nameBuffer)
})
const ffi = require('ffi-napi')
const ref=require('ref-napi')
let path = require('path')
let dllFilePath;

if (process.env.NODE_ENV === 'development') {
   dllFilePath = path.join(process.cwd(), './resources/extraResources','AdbHandler.dll')
} else {
    dllFilePath = path.join(process.cwd(), './resources/extraResources','AdbHandler.dll')
}
let myDll =ffi.Library(dllFilePath, {
    'GetAdbProp':
        [
            ref.types.bool, ['string','char *'],
        ],
})
module.exports = {
    myDll
}

Print the result :

\platform-tools\adb.exe  shell "getprop | grep factory.board"
[factory.board.acclsensor]: [1]
[factory.board.brightness]: [0]
[factory.board.bt]: [1]
[factory.board.charge]: [-1]
[factory.board.cmd]: [0][factory.board.gyrosensor]: [1]
[factory.board.headphone]: [0]
[factory.board.info_check]: [0]
[factory.board.key]: [0]
[factory.board.lcd]: [0]
[factory.board.led]: [0]
[factory.board.mic_hp]: [0]
[factory.board.mic_mic]: [0]
[factory.board.otg]: [0]
[factory.board.psensor]: [0]
[factory.board.sdcard]: [-1]
[factory.board.spk]: [0]
[factory.board.wifi]: [1]
res,nameBuffer
true <Buffer@0x000062140074A800 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ... 10190 more bytes>
>

 const res=myDll.GetAdbProp('factory.board', nameBuffer)

This string of code returns an empty value, and the buffer hasn't changed, but my terminal has something,
How can I use this printout(stduit content),The following these。

\platform-tools\adb.exe  shell "getprop | grep factory.board"
[factory.board.acclsensor]: [1]
[factory.board.brightness]: [0]
[factory.board.bt]: [1]
[factory.board.charge]: [-1]
.....
....
.....

thank you

曾钰涵
  • 11
  • 2
  • Thank you for your warning。 I want to be able to use the content of this console output in my code。 – 曾钰涵 Mar 15 '22 at 01:23
  • ``` const res=myDll.GetAdbProp('factory.board', nameBuffer) ``` This string of code returns an empty value, but my console has STDUIT content 。How do I use it – 曾钰涵 Mar 15 '22 at 01:24
  • Can you please be a bit more clear? What `GetAdbProp` does? Should it modify the `nameBuffer`? –  Mar 15 '22 at 01:32
  • GetAdbProp is a DLL method that passes in a char* argument, returns an int, and modifs the char* that is passed in as a Buffer – 曾钰涵 Mar 15 '22 at 02:27
  • Please provide that part of the code. So we may better understand what's going on there. As the examples above shows nothing, I'm not able to help you. And please make sure to read [How do I ask a good question?](https://stackoverflow.com/help/how-to-ask) before asking any question. –  Mar 15 '22 at 02:38
  • Why are you not invoking `adb` directly, after all it seems that at some point `adb shell` is used? – Diego Torres Milano Mar 15 '22 at 03:49
  • ADB is already called directly, but does not return the result, but I can see ADB output, can I use this ADB print content : [factory.board.acclsensor]: [1] [factory.board.brightness]: [0] [factory.board.bt]: [1] [factory.board.charge]: [-1] – 曾钰涵 Mar 16 '22 at 01:30

0 Answers0