|
-
April 17th, 1999, 05:34 PM
#1
MFC Threads
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;
}
}
-
April 18th, 1999, 02:51 AM
#2
Re: MFC Threads
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
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|