November 28th, 2003, 06:23 AM
need help using thread and socket
i have developed a server socket program which keeps on sending message. i have created a seperate thread using afxbeginthread(SendMsg,this) (this points to the CSocket derived class). im using carchive. the problem is when the thread tries to send messaage i get a debug assertion error.
i dont know what is the cause of the problem.
UINT SendMS(LPVOID lp)
pSock->SendStatus();// here i get error
when i press retry i goes to base class
void CAsyncSocket::AssertValid() const
ASSERT(m_hSocket == INVALID_SOCKET || CAsyncSocket::FromHandle(m_hSocket) != NULL);
outside the thread im able to send the message. i would be happy if u can help me with this problem
November 28th, 2003, 06:36 AM
do NOT pass pointers to MFC objects across threads! NEVER!
pass the m_hWnd's of the objects instead.
see this FAQ and this thread.
November 28th, 2003, 11:57 AM
Post the code the calls the API to send messages. One solution is AfxGetMainWnd().
November 28th, 2003, 02:02 PM
The code in the thread will be running in a different 'scope' from the MFC object you created, and therefore the pointer is invalid.
Click Here to Expand Forum to Full Width
This is a CodeGuru survey question.