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. CreateFile after CloseHandle

CreateFile after CloseHandle

Scheduled Pinned Locked Moved C / C++ / MFC
helpquestion
8 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.
  • A Offline
    A Offline
    aangerma
    wrote on last edited by
    #1

    Hello, I have a problem , Whan I open a port by CreateFile(..) after closing it by CloseHandle(..) the CreateFile fails , I tried to do a Sleep(2000) before reopening its didnt help, on the first time that I am opening it, its succeed it fails just if I open it after closing it. And its happend only in my laptop that have windows 7, on the other computer that have windows XP its work fine. What can be the problem with reopening port after closing it? Thanks!!

    L 1 Reply Last reply
    0
    • A aangerma

      Hello, I have a problem , Whan I open a port by CreateFile(..) after closing it by CloseHandle(..) the CreateFile fails , I tried to do a Sleep(2000) before reopening its didnt help, on the first time that I am opening it, its succeed it fails just if I open it after closing it. And its happend only in my laptop that have windows 7, on the other computer that have windows XP its work fine. What can be the problem with reopening port after closing it? Thanks!!

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      What does GetLastError return after the second CreateFile call?

      A 2 Replies Last reply
      0
      • L Lost User

        What does GetLastError return after the second CreateFile call?

        A Offline
        A Offline
        aangerma
        wrote on last edited by
        #3

        its return ERROR_ACCESS_DENIED

        L 1 Reply Last reply
        0
        • A aangerma

          its return ERROR_ACCESS_DENIED

          L Offline
          L Offline
          Lost User
          wrote on last edited by
          #4

          This[^] appears to be the same problem, you could try if that works.

          1 Reply Last reply
          0
          • L Lost User

            What does GetLastError return after the second CreateFile call?

            A Offline
            A Offline
            aangerma
            wrote on last edited by
            #5

            Thank you its solved my problem

            L 1 Reply Last reply
            0
            • A aangerma

              Thank you its solved my problem

              L Offline
              L Offline
              Lost User
              wrote on last edited by
              #6

              Typical. MS realley messed up with Vista. It seems a lot of the bugs are still there in Win7. This is typical, how the hell does CloeHandle() succeed withouth flushing the data and leaving the port in a state ready to accept a new CreaeFile()? I have written many many drivers for windows, serial drivers, network drivers, and never has one of my serial drivers behaved like this on Visa and Win7.

              ============================== Nothing to say.

              V 1 Reply Last reply
              0
              • L Lost User

                Typical. MS realley messed up with Vista. It seems a lot of the bugs are still there in Win7. This is typical, how the hell does CloeHandle() succeed withouth flushing the data and leaving the port in a state ready to accept a new CreaeFile()? I have written many many drivers for windows, serial drivers, network drivers, and never has one of my serial drivers behaved like this on Visa and Win7.

                ============================== Nothing to say.

                V Offline
                V Offline
                Vaclav_
                wrote on last edited by
                #7

                I found this in my 2001 MSDN CloseHandle invalidates the specified object handle, decrements the object’s handle count, and performs object retention checks. After the last handle to an object is closed, the object is removed from the system. Persistent objects such as databases and files will remain in storage, but must be re-opened to be accessed again. Closing a thread handle does not terminate the associated thread. To remove a thread object, you must terminate the thread, then close all handles to the thread. Use CloseHandle to close handles returned by calls to the CreateFile function. Use FindClose to close handles returned by calls to the FindFirstFile function. I am not sure if newer OS , I run XP, should behave any differently if this is ( bold stuff re-opened ) realy true.

                L 1 Reply Last reply
                0
                • V Vaclav_

                  I found this in my 2001 MSDN CloseHandle invalidates the specified object handle, decrements the object’s handle count, and performs object retention checks. After the last handle to an object is closed, the object is removed from the system. Persistent objects such as databases and files will remain in storage, but must be re-opened to be accessed again. Closing a thread handle does not terminate the associated thread. To remove a thread object, you must terminate the thread, then close all handles to the thread. Use CloseHandle to close handles returned by calls to the CreateFile function. Use FindClose to close handles returned by calls to the FindFirstFile function. I am not sure if newer OS , I run XP, should behave any differently if this is ( bold stuff re-opened ) realy true.

                  L Offline
                  L Offline
                  Lost User
                  wrote on last edited by
                  #8

                  XP set a kind of benchmark, thats why it lasted so long, and later OSs should of course maintain backwards compatability. Clearly they dont in this case, which IMO makes it a bug.

                  ============================== Nothing to say.

                  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