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. Other Discussions
  3. Article Writing
  4. How to close a file opened with CreateFile API

How to close a file opened with CreateFile API

Scheduled Pinned Locked Moved Article Writing
jsontutorialquestion
4 Posts 3 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.
  • S Offline
    S Offline
    SAK
    wrote on last edited by
    #1

    I have opened and successfully read from a text file using CreateFile and ReadFile api's, but how can I close the file. Thank you

    C L 2 Replies Last reply
    0
    • S SAK

      I have opened and successfully read from a text file using CreateFile and ReadFile api's, but how can I close the file. Thank you

      C Offline
      C Offline
      Chris Losinger
      wrote on last edited by
      #2

      CloseHandle -c ------------------------------ Smaller Animals Software, Inc. http://www.smalleranimals.com

      S 1 Reply Last reply
      0
      • C Chris Losinger

        CloseHandle -c ------------------------------ Smaller Animals Software, Inc. http://www.smalleranimals.com

        S Offline
        S Offline
        SAK
        wrote on last edited by
        #3

        Thank you for the information, much appreciated!

        1 Reply Last reply
        0
        • S SAK

          I have opened and successfully read from a text file using CreateFile and ReadFile api's, but how can I close the file. Thank you

          L Offline
          L Offline
          Lim Bio Liong
          wrote on last edited by
          #4

          I assume you are developing in Win32. Use CloseHandle() to close the file. The following is taken from the Win32 documentation for CreateFile() : "Use the CloseHandle function to close an object handle returned by CreateFile." Note that it is very important to call CloseHandle(). Otherwise, the handle table of your application will continue to grow and you will run out of memory in the long term. After closing the handle, it is best to set the value of your handle variable to NULL so that you do not close the handle again. Closing a handle twice will raise an exception.

          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