Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

vbisme

ReadFile() Error

This topic is 6586 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

  
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?

Share this post


Link to post
Share on other sites
Advertisement
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).

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
  
//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);

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
You mean the stdio functions, or iostream functions? Deep down inside they end up calling OS functions anyway....

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!