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. How to use same handle in seperate thread

How to use same handle in seperate thread

Scheduled Pinned Locked Moved C / C++ / MFC
questionhelptutorial
3 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.
  • M Offline
    M Offline
    Mark Lenz
    wrote on last edited by
    #1

    I have a serial port class which continously polls the serial port and writes to the serial port as needed. I have a seperate thread for reading from the serial port. My problem is that I created the handle for the serial port in the main thread to be used when writing to the serial port, but I need to use that same handle in the other thread so that I can read from the serial port. I passed the handle to the worker thread, but I can't use it because it's not part of the thread's handle map. How can I get a handle to the serial port in the worker thread? Mark Lenz

    C B 2 Replies Last reply
    0
    • M Mark Lenz

      I have a serial port class which continously polls the serial port and writes to the serial port as needed. I have a seperate thread for reading from the serial port. My problem is that I created the handle for the serial port in the main thread to be used when writing to the serial port, but I need to use that same handle in the other thread so that I can read from the serial port. I passed the handle to the worker thread, but I can't use it because it's not part of the thread's handle map. How can I get a handle to the serial port in the worker thread? Mark Lenz

      C Offline
      C Offline
      Carlos Antollini
      wrote on last edited by
      #2

      When I need to make that I use a global Variable with the handle that I need to use. For example If I have a conecction with a database, I don't use diferent conections for each handle, I put the connection pointer into a global variable, that is acceded for each handle, and this work, i don't Know if you will have any problem with this practice. I hope to help you... Carlos Antollini. :bob: Is today Friday? No Bob!!!

      1 Reply Last reply
      0
      • M Mark Lenz

        I have a serial port class which continously polls the serial port and writes to the serial port as needed. I have a seperate thread for reading from the serial port. My problem is that I created the handle for the serial port in the main thread to be used when writing to the serial port, but I need to use that same handle in the other thread so that I can read from the serial port. I passed the handle to the worker thread, but I can't use it because it's not part of the thread's handle map. How can I get a handle to the serial port in the worker thread? Mark Lenz

        B Offline
        B Offline
        BruteBertus
        wrote on last edited by
        #3

        take a look at DuplicateHandle, and use 1 handle for writing and the other for reading.. hope this helped :) B.Bruggeman

        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