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. CSocket::Create function has thrown exception

CSocket::Create function has thrown exception

Scheduled Pinned Locked Moved C / C++ / MFC
helplearning
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.
  • E Offline
    E Offline
    Elsie
    wrote on last edited by
    #1

    I have my application run with gflags with Pageheap enabled to track down the page heap corruption. Now the application has crashed and it shows this error, i could not interpret these lines (other than having a feeel of resource inavailablity) Can anyone throw a light on what exactly is the reason that has caused the carsh of the app. [info : Application is a multithreaded one about 500 threads running,in a multi - processor machine) kernel32!RaiseException+53 msvcrt!_CxxThrowException+36 mfc42u!AfxThrowResourceException+19 mfc42u!AfxRegisterWndClass+ab mfc42u!CAsyncSocket::AttachHandle+5c mfc42u!CAsyncSocket::Socket+25 mfc42u!CAsyncSocket::Create+14 Pls help

    M D 2 Replies Last reply
    0
    • E Elsie

      I have my application run with gflags with Pageheap enabled to track down the page heap corruption. Now the application has crashed and it shows this error, i could not interpret these lines (other than having a feeel of resource inavailablity) Can anyone throw a light on what exactly is the reason that has caused the carsh of the app. [info : Application is a multithreaded one about 500 threads running,in a multi - processor machine) kernel32!RaiseException+53 msvcrt!_CxxThrowException+36 mfc42u!AfxThrowResourceException+19 mfc42u!AfxRegisterWndClass+ab mfc42u!CAsyncSocket::AttachHandle+5c mfc42u!CAsyncSocket::Socket+25 mfc42u!CAsyncSocket::Create+14 Pls help

      M Offline
      M Offline
      Moak
      wrote on last edited by
      #2

      Elsie wrote:

      Application is a multithreaded one about 500 threads running

      Do not use CSocket, consider using CAsyncSocket if it has to be MFC based. Also see CSocket considered harmful[^] in the Winsock Programmer's FAQ. /M

      My webchat in Europe :java:

      1 Reply Last reply
      0
      • E Elsie

        I have my application run with gflags with Pageheap enabled to track down the page heap corruption. Now the application has crashed and it shows this error, i could not interpret these lines (other than having a feeel of resource inavailablity) Can anyone throw a light on what exactly is the reason that has caused the carsh of the app. [info : Application is a multithreaded one about 500 threads running,in a multi - processor machine) kernel32!RaiseException+53 msvcrt!_CxxThrowException+36 mfc42u!AfxThrowResourceException+19 mfc42u!AfxRegisterWndClass+ab mfc42u!CAsyncSocket::AttachHandle+5c mfc42u!CAsyncSocket::Socket+25 mfc42u!CAsyncSocket::Create+14 Pls help

        D Offline
        D Offline
        decentsmile
        wrote on last edited by
        #3

        Hi Guys, This same problem has driven me nuts but finally i fixed it and it is working. This is bug with MFC socket library that when inside a thread [other than main application thread], If we try to do something like CSocket socket; socket.Create(); It will throws an unhandled exception. I found an article on it See What Microsoft says about this that said something from Microsoft but that did not help me either. So here is a workaround i have found and i hope it can help some frustrated fellow like me. Inside thread, do this CSocket mySock; SOCKET sockethandle = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP); mySock.m_hSocket= sockethandle; After that DO NOT call mySock.Create as it has been created already through assignment of socket handle. I am not sure if we can use mySock.Attach(sockethandle) as i did not try it yet. After that you can call Connect etc directly. When you are done using the socket, DO NOT call

        - rather call closesocket(mySock.m_hSocket); And that will free the socket object. If Attach works in above case then i guess we need to do Detach here when to free the socket. Good Luck Nauman Khan

        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