Ok, well, I got the MFC multi-threading working. I found some code on CodeProject.com. Now I have another problem. I defined my Listen() and Server() functions in my application's dialog class, and I had to make them 'static UINT Function()', etc. Now, when I use "AfxSocketInit(NULL)", where the parameter is "WSADATA*", it causes the problem. First, I used some code from CodeProject. It looks like this:
Code:
typedef struct
{
CMyApplicationDlg *_this; // Class's 'this' pointer
} THREADSTRUCT;
I have to use that so that I am able to access functions in the class from my 'static' member functions, since I can't directly access non-static class members from a static class member. When I do something similar to this:
Code:
// 'lpParam' is the parameter passed in "AfxBeginThread"
THREADSTRUCT *ts = (THREADSTRUCT*) lpParam;
// This causes the problem
ts->_this->m_csListen.Accept(m_csClient);
It gives me an error, and when I do "Debug", I get this line, from sockcore.cpp (I think that's the filename):
Code:
ASSERT(pState->m_hSocketWindow != NULL);
I think it's because my thread functions (Listen() and Server()) cannot access the dialog class so they can use the dialog window as the socket window. If you can offer any help I would really appreciate it.