Using readfile()
-
Does anyone have any examples on how to use the readfile() function. This is my first time to use it and I'm taking the instructions straight from MSDN and it's not working. Here is what I have. HANDLE fptr; bool bResult; LPVOID inBuffer; DWORD nBytesToRead = 20; LPDWORD nBytesRead = 0; bResult = ReadFile(fptr, &inBuffer, nBytesToRead, nBytesRead, NULL); I don't think I fully understand how the function works.
-
Does anyone have any examples on how to use the readfile() function. This is my first time to use it and I'm taking the instructions straight from MSDN and it's not working. Here is what I have. HANDLE fptr; bool bResult; LPVOID inBuffer; DWORD nBytesToRead = 20; LPDWORD nBytesRead = 0; bResult = ReadFile(fptr, &inBuffer, nBytesToRead, nBytesRead, NULL); I don't think I fully understand how the function works.
There are many problems with the code you posted... these parts are OK: Camron wrote: HANDLE fptr; bool bResult; DWORD nBytesToRead = 20; But here are the problems...
LPVOID inBuffer; // declares a pointer to wherever you will store input, but no memory allocated for it. LPDWORD nBytesRead = 0; // declares a pointer to a DWORD to receive the number of bytes read, but no memory to store it.
These should be similar to the following:UCHAR inBuffer[10000]; // or whatever size you want DWORD nBytesRead = 0; // we'll cast to a pointer later
Now with those changes, there is one more step before you can read... fptr is a handle to a file - you haven't opened a file yet! Now your attempt to read would become:bResult = ReadFile(fptr, inBuffer, nBytesToRead, &nBytesRead, NULL);
After you read, you can close the file. Hope that helps. Karl - WK5M PP-ASEL-IA (N43CS) PGP Key: 0xDB02E193 PGP Key Fingerprint: 8F06 5A2E 2735 892B 821C 871A 0411 94EA DB02 E193