如何正确创建和读取指向节点ffi中结构数组的指针

时间:2018-11-21 10:06:32

标签: node.js winapi node-ffi

Node-ffi缺少文档

我正在尝试使用此功能https://docs.microsoft.com/en-us/windows/desktop/api/ras/nf-ras-rasenumconnectionsw

const ffi = require( 'ffi-napi' );
const ref = require( 'ref' );

var myobj = ref.types.void;
var myobjPtr = ref.refType( myobj );
var myobjPtrPtr = ref.refType( myobjPtr );
var long1 = ref.refType( 'long' );
var long2 = ref.refType( 'long' );

var firstVar = ref.alloc( myobjPtrPtr );
var longVar1 = ref.alloc( 'long' );
var longVar2 = ref.alloc( 'long' );

let ras = new ffi.Library( 'Rasapi32.dll', {
  'RasEnumConnectionsW': [
    'long', // Return value - DWORD
    [ // Arguments
      // Pointer to a buffer that receives, on output, an array of RASCONN structures,
      // one for each RAS connection.
      myobjPtrPtr, // LPRASCONNW

      // Pointer to a variable that, on input, contains the size, in bytes, of the buffer
      // specified by lprasconn.
      long1, // LPDWORD

      // Pointer to a variable that receives the number of RASCONN structures written to
      // the buffer specified by lprasconn.
      long2 // LPDWORD
    ]
  ]
});

ras.RasEnumConnectionsW( firstVar, longVar1, longVar2 );

console.log( ref.deref( firstVar ) );

现在node-ffi给出UintArray8。不是字符串数组,不是对象数组

0 个答案:

没有答案