我正在尝试使用 node-ffi 与 win32 api FormatMessageA 进行交互,但是我似乎无法获取 out lpBuffer 参数,这是一段代码来显示我尝试过的内容
'use strict';
const ref = require('ref');
const ffi = require('ffi');
const Kernel32 = ffi.Library('Kernel32.dll', {
FormatMessageA: ['ulong', [
'ulong', //flags
'void *',
'ulong', //status number
'ulong', //language
'uchar *',
'ulong',
'void *'
]]
});
const FORMAT_MESSAGE_FROM_SYSTEM = 0x1000;
const FORMAT_MESSAGE_ALLOCATE_BUFFER = 0x100;
const FORMAT_MESSAGE_IGNORE_INSERTS = 0x200;
const lpBuffer = ref.alloc('uchar *');
const result = Kernel32.FormatMessageA(
FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_IGNORE_INSERTS,
null,
0x80090300, //error code
0,
lpBuffer,
0,
null
);
console.log(result); //prints 57 bytes
我知道函数是成功的,因为它返回 57 但是我无法获得包含我需要的错误字符串的 lpBuffer 值。