Click to See Complete Forum and Search --> : MFC Threads


April 17th, 1999, 05:34 PM
I'm trying to create a worker thread in MFC and have the following code. Anyway, basically I want to thread the MyThredProc function. However, the compiler keeps giving me the error "error C2665: 'AfxBeginThread' : none of the 2 overloads can convert parameter 1 from type 'unsigned int (void *)'". I can't figure out the reason for this. Any one have any ideas? Thanks!!!

Vince


UINT CTestView::MyThreadProc(LPVOID pParam)
{
int i = 0;

while (i == 0) {
CClientDC dc(this);
dc.TextOut(1, 1, "Hello");
}

return 0;
}

void CTestView::OnChar(UINT nChar, UINT nRepCnt, UINT nFlags)
{
// TODO: Add your message handler code here and/or call default

LPVOID pParam = NULL;

switch (nChar)
{
case 'L':
AfxBeginThread(MyThreadProc, pParam);
break;
case 'M':
MessageBox("This thread works!");
break;
default:
CView::OnChar(nChar, nRepCnt, nFlags);
break;
}


}

klussier
April 18th, 1999, 02:51 AM
It looks like the problem is that you're trying to use a non-static member function in your call to AfxBeginThread. In C++, every non-static member function has an implied extra paramater which is the 'this' pointer of the class. Thus, your function declaration really looks like:
UINT CTestView::MyThreadProc(CTestView *this, LPVOID pParam)

To get around this, you must either use a non-member function, or declare your function as static (this has implications too, however, so be careful).

Hope this helps...

Kevin