|
In CMyDialog:
CSocket m_pSocket;
CMyThread m_pThread;
In CMyDialog :: InitDialog ()
m_pSocket = new CSocket ();
m_pSocket-> Create (MYPORT);
... Socket generation is perfectly fine
m_pThread = AfxBeginThread (RUNTIME_CLASS (CMyThread)); The establishment of Thread is also no problem at all
In CMyDialog :: OnMyButtonClick ()
m_pThread-> PostThreadMessage (MYMESSAGE);
In the CMyThread message loop:
case MYMESSAGE:
(This is a CMyDlg class global variable generated when the Thread is initialized)
m_pDlg-> RecvData ();
Everything was fine before:
But when m_pThread executes CMyDlg :: RecvData ()
CMyDlg :: RecvData () {
m_pSocket-> send (...) Here m_pSocket == 0, there is no problem if you use this-> RecvData () without going through the thread, why?
Does the CSocket class have a dependency on its spawning thread? |
|