问题
I'm using (while not being quite sure about lpBuffer -> char.ptr)
let readFile = kernel32.declare(
"ReadFile",
ctypes.winapi_abi,
ctypes.int32_t, //bool // return type: 1 indicates success, 0 failure
ctypes.voidptr_t, // in: hObject
ctypes.char.ptr, // out: lpBuffer
ctypes.uint32_t, // in: lpNumberOfBytesRead
ctypes.uint32_t.ptr, // out: lpNumberOfBytesWritten
ctypes.voidptr_t.ptr // inout: lpOverlapped
);
for
BOOL WINAPI ReadFile(
_In_ HANDLE hFile,
_Out_ LPVOID lpBuffer,
_In_ DWORD nNumberOfBytesToRead,
_Out_opt_ LPDWORD lpNumberOfBytesRead,
_Inout_opt_ LPOVERLAPPED lpOverlapped
);
However, when I try
let output = ctypes.char.array(1024);
let isRead = readFile(hFile, output, 1024, bytesWritten.address())
I get
JPM [error] Message: TypeError: can't pass ctypes.char.array(1024) to argument 2 of int32_t ReadFile(void*, char*, uint32_t, void**)
More attempts.
let output = ctypes.char.array(1024);
let isRead = readFile(hFile, output.ptr, 1024, bytesWritten.address())
JPM [error] Message: TypeError: can't pass ctypes.char.array(1024).ptr to argument 2 of int32_t ReadFile(void*, char*, uint32_t, void**
let output = ctypes.char.array(1024);
let isRead = readFile(hFile, output.address(), 1024, bytesWritten.address())
JPM [error] Message: TypeError: output.address is not a function
let output = ctypes.char.ptr;
let isRead = readFile(hFile, output, 1024, bytesWritten.address())
JPM [error] Message: TypeError: can't pass ctypes.char.ptr to argument 2 of int32_t ReadFile(void*, char*, uint32_t, v oid**)
回答1:
This made it work
let outputType = ctypes.char.array(1024);
let output = outputType();
let isRead = readFile(hFile, output, 1024, bytesWritten.address(), null);
来源:https://stackoverflow.com/questions/36031573/using-js-ctypes-how-do-i-retrieve-output-from-windows-readfile