CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5
  1. #1
    Join Date
    Nov 2008
    Location
    Cebu, Philippines
    Posts
    19

    Question ASSERT(m_hSocket == INVALID_SOCKET) Error

    Hello MFC networking gurus. i'm having some trouble in my program. It generates an access violation runtime error and when i debug it, it points to the assertion in the title.

    it's a client based CSocket Application where all i did was follow the normal flow.
    1. AfxSocketInit()
    2. CreateSocket();
    3. Connect();

    the error occurs in the create part.

    a little detailed design of the program is:
    Code:
    class CSockMgrDLGDlg : public CDialog
    {
       //other functions and attributes
      private:
          CommunicationMgr *oComMgr;
    };
    
    class CommunicationMgr
    {
        //other functions and attributes
        private:
            CSocketMgr  *oSocketMgr;
    }
    
    class CSocketMgr : public CSocket
    {
        //some functions and attributes
    };
    CSockMgrDLGDlg uses CommunicationMgr for connectivity. CSockMgrDLGDlg calls the CommunicationMgr::Connect() function
    and CommunicationMgr::Connect calls CSocket::Connect() that goes for XXX::Create() too.



    Question:
    1. what do you think are the possible reasons that this access violation error is occurring?
    2. will there be some hidden bugs/runtime errors created if CSockMgrDLGDlg doesn't use CSocketMgr directly?

    thank you very much in advance..
    Last edited by klambiguit; November 12th, 2008 at 05:17 AM. Reason: added details..

  2. #2
    Join Date
    Aug 2007
    Location
    Birmingham, UK
    Posts
    360

    Re: ASSERT(m_hSocket == INVALID_SOCKET) Error

    A possible reason for this is something you do in your code. Which, unfortunately, you did not post, so there is pretty little anybody can say about this case.. Please post the relevant code (and please do use code tags).

  3. #3
    Join Date
    Nov 2008
    Location
    Cebu, Philippines
    Posts
    19

    Re: ASSERT(m_hSocket == INVALID_SOCKET) Error


  4. #4
    Join Date
    Nov 2008
    Location
    Cebu, Philippines
    Posts
    19

    Re: ASSERT(m_hSocket == INVALID_SOCKET) Error

    found it!! thanks!!

    it was a stupid mistake..!

    there are two constructors in CCommunicationMgr Class.

    what i've used is the default constructor w/c does not instantiate the CSocketMgr class w/c is why there is an access violation.. :sigh:

    the other constructor instantiates the CSocketMgr Class.

  5. #5
    Join Date
    Nov 2008
    Location
    Cebu, Philippines
    Posts
    19

    Re: ASSERT(m_hSocket == INVALID_SOCKET) Error

    a follow up question, everything works fine now.. my client can connect but after connection, why does it consume sooooo much memory? i can't detect the leak.. please help...

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured