Skip to main content
GameDev.net gamedev.net
🔒 Locked

ReadFile() Error

Started by vbisme Nov 30, 2000 at 10:34 PM 5 replies 300+ views
Original Post
vbisme
vbisme
  
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?
Quantum
Quantum
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).
vbisme
vbisme
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
vbisme
vbisme
  
//in DLL

class GFXFileInfo
{
public:
long NumberOfFiles;
long TotaDataSize;
};

LINKDLL GFXFileInfo LoadGFXFile(LPCTSTR FileName, PBYTE & rGFXFile)
{
HANDLE hFile; //file handle

GFXFileInfo GFXfileinfo;
LPDWORD NumBytesRead = NULL; //indications

DWORD FileSize, FileSizeHigh, LastError;

///Open the file for reading

hFile = 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 File

rGFXFile = (PBYTE)malloc(GFXfileinfo.TotaDataSize);
///Read the opened file into pointer

ReadFile(hFile, rGFXFile, FileSize, NumBytesRead, NULL);
return(GFXfileinfo);
}

//Main function:

PBYTE pGFXFileContainer;
GFXFileInfo FileInfo;
FileInfo = LoadGFXFile("filename.gfx", pGFXFileContainer);

SiCrane
SiCrane
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.
Beer Hunter
Beer Hunter
I have used ReadFile myself, but I was just wondering, is it faster to use a compiler''s built-in file access?
SiCrane
SiCrane
You mean the stdio functions, or iostream functions? Deep down inside they end up calling OS functions anyway....

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.