Click to See Complete Forum and Search --> : Threads - why so hard


August 25th, 1999, 12:21 PM
I want to make a simple worker thread. This is my first time using threads
in an MFC app. But AfxBeginThread and _beginthread give compile errors.

'_beginthread': cannot convert parameter 1 from 'void(void*)' to 'void(__cdecl*)(void*)'

All the examples in the books look so simple, but I get compile errors.
I've tried all kinds of casts, but I do not think this is the problem.

Can anyone help?

I have VC++ 6.0 with no service packs.


void CLeftView::thread_OnUpdate(void *param)
{
int status;
CTreeCtrl &treeCtl = this->GetTreeCtrl();
CViewerDoc *pDoc = GetDocument();
void *db_handle_p;
cell_hdr_ptr_t cell_hdr_p;

(&treeCtl)->DeleteAllItems();

CCL_DBHandle_Get(&db_handle_p, pDoc->ccl_handle_p);
Db_Topcell_Get(&cell_hdr_p,db_handle_p);

// Now populate the tree view
{
CWaitCursor wait;
PopulateTreeView(&treeCtl, db_handle_p, cell_hdr_p, &status);
}
}

void CLeftView::OnUpdate(CView* pSender, LPARAM lHint, CObject* pHint)
{
// CWinThread *worker = AfxBeginThread(thread_OnUpdate, this);
_beginthread(thread_OnUpdate,0,this);
}





David Figueiredo
davidf@etec.com

August 25th, 1999, 12:39 PM
Use Global function instead of member func.
Ex:
void CDownloadView::OnInitialUpdate()
{
CListView::OnInitialUpdate();

hDownload= CreateThread( NULL, 0L, CheckDownloadFiles,
( LPVOID )&st1, 0, &thId );
}

DWORD WINAPI CheckDownloadFiles( LPVOID lParam )
{

//code...
}

ALM
August 25th, 1999, 01:21 PM
You can and should use AfxBeginThread. It's easier and more flexible to work with than _beginthread...

The first problem I see is that your thread function (thread_OnUpdate) is not in the right signature:

UINT CLeftView::thread_OnUpdate(LPVOID pParam)

The second thing which MAY be wrong is that your thread function is not static. In other words, the thread function cannot be a regular member function. It must be static or global.

That should take care of it. Good luck!
Alvaro