Advertisement

ReadFile() Error

Started by November 30, 2000 10:34 PM
5 comments, last by vbisme 24 years, 1 month ago
  
long myLong;
ReadFile(hFile, &myLong, sizeof(long), NumBytesRead, NULL);
LastError = GetLastError();
  
LastError = 87 which is The parameter is incorrect. ERROR_INVALID_PARAMETER I don''t understand, I''ve been using ReadFile() ever since. I tested all the functions before it and no error. What''s wrong?
Unless NumBytesRead is a pointer, I think you need to pass it &NumBytesRead as the 4th parameter is an LPDWORD. (This is just from what I just read out of the MSDN.. might be completely wrong).
Advertisement
I declared it as
      LPDWORD NumBytesRead;    


If it wasn't I would get a compile error:
error C2664: 'ReadFile' : cannot convert parameter 4 from 'unsigned long' to 'unsigned long *'

so....not that.

Hmmm, what seems to be the problem is that previous I put the codes in a function in a .dll ... but when I implimented the code locally, nothing is wrong. Hmmm something wrong with the function call?


Edited by - vbisme on November 30, 2000 12:15:39 AM
  //in DLLclass GFXFileInfo{public:	long NumberOfFiles;	long TotaDataSize;};LINKDLL GFXFileInfo LoadGFXFile(LPCTSTR FileName, PBYTE & rGFXFile){HANDLE		hFile;	//file handleGFXFileInfo	GFXfileinfo;LPDWORD		NumBytesRead = NULL;	//indicationsDWORD		FileSize, FileSizeHigh, LastError;///Open the file for readinghFile = CreateFile(FileName, GENERIC_READ, 0, NULL, OPEN_EXISTING, FILE_FLAG_SEQUENTIAL_SCAN, NULL);//ReadFile(hFile, &GFXfileinfo, sizeof(GFXFileInfo), NumBytesRead, NULL);GFXfileinfo.TotaDataSize = GetFileSize(hFile, &FileSizeHigh);///Get the number of files///Allocate memory for pointer to GFX FilerGFXFile = (PBYTE)malloc(GFXfileinfo.TotaDataSize);///Read the opened file into pointerReadFile(hFile, rGFXFile, FileSize, NumBytesRead, NULL);return(GFXfileinfo);}//Main function:PBYTE			pGFXFileContainer;GFXFileInfo		FileInfo;FileInfo = LoadGFXFile("filename.gfx", pGFXFileContainer);    

The fourth parameter to ReadFile cannot be NULL. The easiest way to fix that would be to redeclare NumBytesRead as a LONG and instead pass it''s address to ReadFile.
I have used ReadFile myself, but I was just wondering, is it faster to use a compiler''s built-in file access?
Advertisement
You mean the stdio functions, or iostream functions? Deep down inside they end up calling OS functions anyway....

This topic is closed to new replies.

Advertisement