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!
Opening Files: very weird error.
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
int iOK = ReadFile(filehandle, p_byBuffer, sizeof(structuretoread), &dwRead, 0);
if (!ok || dwRead != sizeof(structuretoread) )
//error handling code here.
Hope this helps fatty
Aface
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement