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. Socket and thread

Socket and thread

Scheduled Pinned Locked Moved C / C++ / MFC
question
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
    mehrdadov
    wrote on last edited by
    #1

    Hello I create a CSocket object then I post it to a thread but when I post it to thread, posted object(pointer) is not valid in thread how can I create a socket out of thread and send it to thread? thanks Mehrdad

    K M 2 Replies Last reply
    0
    • M mehrdadov

      Hello I create a CSocket object then I post it to a thread but when I post it to thread, posted object(pointer) is not valid in thread how can I create a socket out of thread and send it to thread? thanks Mehrdad

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

      Your question does not seem to be very clear. How do you create the CSocket object? If it is like: CSocket sock; ...Initialize it etc. CreateThread(... , (void*)&sock...); //etc Then it is not going to work, because the object is being created on the stack and will be destroyed when the calling function exits. Create it on the heap etc: CSocket* pSock; pSock = new CSocket; ...Initialize it etc. Then send it to the thread. Hope that helps. this is this.

      1 Reply Last reply
      0
      • M mehrdadov

        Hello I create a CSocket object then I post it to a thread but when I post it to thread, posted object(pointer) is not valid in thread how can I create a socket out of thread and send it to thread? thanks Mehrdad

        M Offline
        M Offline
        Michael Dunn
        wrote on last edited by
        #3

        Many types of MFC objects can't be passed between threads becaues MFC keeps per-thread data structures. Pass the SOCKET handle to the thread then call CSocket::FromHandle() --Mike-- Visual C++ MVP :cool: LINKS~! Ericahist | NEW!! PimpFish | CP SearchBar v3.0 | C++ Forum FAQ

        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