任何人都可以帮助我,因为这里出了什么问题? 我无法使用malloc分配内存......
bReadFile = ReadFile( hConsoleFile, &ReadFileBuffer, MaxCharToRead, &CharsRead, NULL );
答案 0 :(得分:3)
ReadFile
的来电中有&ReadFileBuffer
。您应该将ReadFile
指针传递给缓冲区,而不是指向缓冲区的指针。
lpBuffer [out]
A pointer to the buffer that receives the data read from a file or device.
由于ReadFileBuffer
是指向缓冲区的指针,这就是你应该传递的内容。
答案 1 :(得分:1)
ReadFile()
的签名是:
BOOL WINAPI ReadFile(
__in HANDLE hFile,
__out LPVOID lpBuffer,
__in DWORD nNumberOfBytesToRead,
__out_opt LPDWORD lpNumberOfBytesRead,
__inout_opt LPOVERLAPPED lpOverlapped
);
第二个参数应该是指向缓冲区的指针,而不是指向缓冲区指针的指针。这就是你&ReadFileBuffer
时所得到的。电话应该是:
bReadFile = ReadFile(hConsoleFile, ReadFileBuffer, MaxCharToRead, &CharsRead, NULL);