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. CAyncSocket::Detach Fails _AFX_SOCK_THREAD_STATE* pState-> m_hSocketWindow == NULL

CAyncSocket::Detach Fails _AFX_SOCK_THREAD_STATE* pState-> m_hSocketWindow == NULL

Scheduled Pinned Locked Moved C / C++ / MFC
c++sysadminjsonannouncement
5 Posts 3 Posters 1 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.
  • F Offline
    F Offline
    ForNow
    wrote on last edited by
    #1

    hI I create four CAsynSocket Classes in four CwinThread classes When I first create them Socket (with notification events) bind ioctl, setsockopt. I follow the CASynSocket::Socket call to sockcore.cpp and

    pState-> m_hSocketWindow

    has a valid Hwnd Value. The context of the creation of sockets in the CwinApp after my main CFrameWnd has been created. I then start a conversation with the server (connect send and then receive). It is at a point that I would like to give the work over to a modeless dialog. this is where things go wrong. After getting a message from the server I try to do a detach which goes to

    CAsyncSocket::AsyncSelect(long lEvent)

    however at this point

    _AFX_SOCK_THREAD_STATE* pState-> m_hSocketWindow == NULL

    is NULL Since I was debugging this in release mode I never got the subsequent assert on this. First off in the documentation for CAsynSocket there is no mention that i need a Hwnd to process the class when I first did the CAsynSocket::Socket call with the event notification that I wanted to be informed on I did notice that

    pState-> m_hSocketWindow

    had a valid window When I first started using CAsyncSocket I know very little about TCPI/IP or OO at this point looking at Winscok API it has much more flexability so much so it seem I dont necessary need a valid Hwnd but a kernel object such as that from CreateEvent will do more so It seems if I want to pass notification to a different windows I just do another call to

    WSAAsyncSelect

    with a new HWND Still I am wondering why

    pState-> m_hSocketWindow

    went to NULL

    Mircea NeacsuM V 2 Replies Last reply
    0
    • F ForNow

      hI I create four CAsynSocket Classes in four CwinThread classes When I first create them Socket (with notification events) bind ioctl, setsockopt. I follow the CASynSocket::Socket call to sockcore.cpp and

      pState-> m_hSocketWindow

      has a valid Hwnd Value. The context of the creation of sockets in the CwinApp after my main CFrameWnd has been created. I then start a conversation with the server (connect send and then receive). It is at a point that I would like to give the work over to a modeless dialog. this is where things go wrong. After getting a message from the server I try to do a detach which goes to

      CAsyncSocket::AsyncSelect(long lEvent)

      however at this point

      _AFX_SOCK_THREAD_STATE* pState-> m_hSocketWindow == NULL

      is NULL Since I was debugging this in release mode I never got the subsequent assert on this. First off in the documentation for CAsynSocket there is no mention that i need a Hwnd to process the class when I first did the CAsynSocket::Socket call with the event notification that I wanted to be informed on I did notice that

      pState-> m_hSocketWindow

      had a valid window When I first started using CAsyncSocket I know very little about TCPI/IP or OO at this point looking at Winscok API it has much more flexability so much so it seem I dont necessary need a valid Hwnd but a kernel object such as that from CreateEvent will do more so It seems if I want to pass notification to a different windows I just do another call to

      WSAAsyncSelect

      with a new HWND Still I am wondering why

      pState-> m_hSocketWindow

      went to NULL

      Mircea NeacsuM Offline
      Mircea NeacsuM Offline
      Mircea Neacsu
      wrote on last edited by
      #2

      It's probably not fair to send you down a different path, but many years ago I had similar problems and, having some spare time, I decided to make my own set of wrappers for Windows Sockets API. Over time it has grown into a quite capable set of objects that allow you to work with sockets just like you work with C++ streams. I've wrote a series of articles here and you can take a look see if they are of any help to you: - Windows Sockets Streams[^] - Windows Sockets Streams Part II - Multi-Threaded TCP Servers[^] - Windows Sockets Streams Part III - HTTP Server[^] Latest version of code can be downloaded from GitHub[^].

      Mircea

      F 1 Reply Last reply
      0
      • F ForNow

        hI I create four CAsynSocket Classes in four CwinThread classes When I first create them Socket (with notification events) bind ioctl, setsockopt. I follow the CASynSocket::Socket call to sockcore.cpp and

        pState-> m_hSocketWindow

        has a valid Hwnd Value. The context of the creation of sockets in the CwinApp after my main CFrameWnd has been created. I then start a conversation with the server (connect send and then receive). It is at a point that I would like to give the work over to a modeless dialog. this is where things go wrong. After getting a message from the server I try to do a detach which goes to

        CAsyncSocket::AsyncSelect(long lEvent)

        however at this point

        _AFX_SOCK_THREAD_STATE* pState-> m_hSocketWindow == NULL

        is NULL Since I was debugging this in release mode I never got the subsequent assert on this. First off in the documentation for CAsynSocket there is no mention that i need a Hwnd to process the class when I first did the CAsynSocket::Socket call with the event notification that I wanted to be informed on I did notice that

        pState-> m_hSocketWindow

        had a valid window When I first started using CAsyncSocket I know very little about TCPI/IP or OO at this point looking at Winscok API it has much more flexability so much so it seem I dont necessary need a valid Hwnd but a kernel object such as that from CreateEvent will do more so It seems if I want to pass notification to a different windows I just do another call to

        WSAAsyncSelect

        with a new HWND Still I am wondering why

        pState-> m_hSocketWindow

        went to NULL

        V Offline
        V Offline
        Victor Nijegorodov
        wrote on last edited by
        #3

        I'd recommend you to check out this great Joe Newcomer's essay: [A Rewrite of KB192570: An MFC Asynchronous Socket Example Done Right](http://www.flounder.com/kb192570.htm)

        F 1 Reply Last reply
        0
        • Mircea NeacsuM Mircea Neacsu

          It's probably not fair to send you down a different path, but many years ago I had similar problems and, having some spare time, I decided to make my own set of wrappers for Windows Sockets API. Over time it has grown into a quite capable set of objects that allow you to work with sockets just like you work with C++ streams. I've wrote a series of articles here and you can take a look see if they are of any help to you: - Windows Sockets Streams[^] - Windows Sockets Streams Part II - Multi-Threaded TCP Servers[^] - Windows Sockets Streams Part III - HTTP Server[^] Latest version of code can be downloaded from GitHub[^].

          Mircea

          F Offline
          F Offline
          ForNow
          wrote on last edited by
          #4

          Thanks talk about fair I don’t think it’s fair for Microsoft to Have us use CAsyncSocket Just my opinion

          1 Reply Last reply
          0
          • V Victor Nijegorodov

            I'd recommend you to check out this great Joe Newcomer's essay: [A Rewrite of KB192570: An MFC Asynchronous Socket Example Done Right](http://www.flounder.com/kb192570.htm)

            F Offline
            F Offline
            ForNow
            wrote on last edited by
            #5

            He has a detach on the server side more so before any conversation gets going My scenario involves the main windows looks if anyone wants to start a conversation with the server if I see it happens a conversation with the server is initiated I want to pass off that socket to a mode less dialog Thanks

            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