Click to See Complete Forum and Search --> : ASSERT(m_hSocket == INVALID_SOCKET) Error


klambiguit
November 12th, 2008, 01:56 AM
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:

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..

Edders
November 12th, 2008, 04:09 AM
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).

klambiguit
November 12th, 2008, 04:25 AM
sorry about that...
i uploaded the code

23711

23712

23713

23714

23717

klambiguit
November 12th, 2008, 07:53 AM
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.

klambiguit
November 12th, 2008, 08:12 AM
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... :sick: