Can anyone help me as what is going wrong here? Am not able to allocate memory using malloc...
bReadFile = ReadFile( hConsoleFile, &ReadFileBuffer, MaxCharToRead, &CharsRead, NULL );
Can anyone help me as what is going wrong here? Am not able to allocate memory using malloc...
bReadFile = ReadFile( hConsoleFile, &ReadFileBuffer, MaxCharToRead, &CharsRead, NULL );
You have &ReadFileBuffer
in the call to ReadFile
. You are supposed to pass ReadFile
a pointer to the buffer, not a pointer to a pointer to the buffer.
From the documentation:
lpBuffer [out]
A pointer to the buffer that receives the data read from a file or device.
Since ReadFileBuffer
is a pointer to the buffer, that's what you should be passing.
The signature for ReadFile()
is this:
BOOL WINAPI ReadFile(
__in HANDLE hFile,
__out LPVOID lpBuffer,
__in DWORD nNumberOfBytesToRead,
__out_opt LPDWORD lpNumberOfBytesRead,
__inout_opt LPOVERLAPPED lpOverlapped
);
The second parameter should be a pointer to your buffer, not a pointer to a pointer to your buffer. That's what you got when you did &ReadFileBuffer
. The call should be:
bReadFile = ReadFile(hConsoleFile, ReadFileBuffer, MaxCharToRead, &CharsRead, NULL);