Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Using readfile()

Using readfile()

Scheduled Pinned Locked Moved C / C++ / MFC
tutorial
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • C Offline
    C Offline
    Camron
    wrote on last edited by
    #1

    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.

    K 1 Reply Last reply
    0
    • C Camron

      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.

      K Offline
      K Offline
      krmed
      wrote on last edited by
      #2

      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

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups