Opening Files: very weird error.

Started by
14 comments, last by Nacho 21 years, 7 months ago
Ok, I tried to rewrite the function using the Win32 File I/O functions, but there´s a little tiny thing I don´t understand about one of them: ReadFile(). Its 4th parameter:

LPDWORD lpNumberOfBytesRead, // pointer to number of bytes read

MSDN says:

lpNumberOfBytesRead
Pointer to the number of bytes read. ReadFile sets this value to zero before doing any work or error checking. If this parameter is zero when ReadFile returns TRUE on a named pipe, the other end of the message-mode pipe called the WriteFile function with nNumberOfBytesToWrite set to zero.
Windows 95 and Windows 98: This parameter cannot be NULL.

I read the explanation many times but I´m not sure about what to pass in this parameter. Can you help me with this one? Thanks a lot!
Advertisement
DWORD numBytesRead;

ReadFile(...... &numBytesRead .....);
ReactOS - an Open-source operating system compatible with Windows NT apps and drivers
quote:Original post by Martee
DWORD numBytesRead;

ReadFile(...... &numBytesRead .....);


Do I have to use that pointer later? Is it useful?

Well in Windows 95 & 98 you need to pass a dummy variable. Regardless of whether you use it or not, a variable must be passed on those Windows versions. It could be useful later when debugging your code however.
You pass a reference to a DWORD and the function stores the number of actual number of bytes read into your buffer. So a check on the function working correctly might look something like this

int iOK = ReadFile(filehandle, p_byBuffer, sizeof(structuretoread), &dwRead, 0);

if (!ok || dwRead != sizeof(structuretoread) )
//error handling code here.

Hope this helps fatty
Aface


Thanks for all the replies! The functions is working fine now.

This topic is closed to new replies.

Advertisement