CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Guest

    Threads - why so hard

    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
    [email protected]


  2. #2
    Guest

    Re: Threads - why so hard

    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...
    }



  3. #3
    Join Date
    Jun 1999
    Location
    Miami, FL
    Posts
    972

    Re: Threads - why so hard

    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


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured