Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. AfxBeginThread() ???

AfxBeginThread() ???

Scheduled Pinned Locked Moved C / C++ / MFC
helpquestion
5 Posts 5 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    Static x
    wrote on last edited by
    #1

    Hi i want to write a simple thread , that will work in the background and i'll be able to do other things in my program until the thread is in progress,i do the following but get an error. UINT CtestDlg::MyThreadProc(LPVOID pParam)//create thread { for(int i=0;i<10000;i++) for(int j=0;j<10000;j++) {}; MessageBox("Finished"); return 0; } then call it : AfxBeginThread(MyThreadProc,0); but i get an error : c:\...\ : error C2665: 'AfxBeginThread' : none of the 2 overloads can convert parameter 1 from type 'UINT (LPVOID)' Can anyone help ? Regards Giorgi Moniava

    M G 2 Replies Last reply
    0
    • S Static x

      Hi i want to write a simple thread , that will work in the background and i'll be able to do other things in my program until the thread is in progress,i do the following but get an error. UINT CtestDlg::MyThreadProc(LPVOID pParam)//create thread { for(int i=0;i<10000;i++) for(int j=0;j<10000;j++) {}; MessageBox("Finished"); return 0; } then call it : AfxBeginThread(MyThreadProc,0); but i get an error : c:\...\ : error C2665: 'AfxBeginThread' : none of the 2 overloads can convert parameter 1 from type 'UINT (LPVOID)' Can anyone help ? Regards Giorgi Moniava

      M Offline
      M Offline
      Michael Dunn
      wrote on last edited by
      #2

      See the FAQ 6.1 Why can't I use a member function as a callback?[^] --Mike-- LINKS~! Ericahist | 1ClickPicGrabber | CP SearchBar v2.0.2 | C++ Forum FAQ Strange things are afoot at the U+004B U+20DD

      1 Reply Last reply
      0
      • S Static x

        Hi i want to write a simple thread , that will work in the background and i'll be able to do other things in my program until the thread is in progress,i do the following but get an error. UINT CtestDlg::MyThreadProc(LPVOID pParam)//create thread { for(int i=0;i<10000;i++) for(int j=0;j<10000;j++) {}; MessageBox("Finished"); return 0; } then call it : AfxBeginThread(MyThreadProc,0); but i get an error : c:\...\ : error C2665: 'AfxBeginThread' : none of the 2 overloads can convert parameter 1 from type 'UINT (LPVOID)' Can anyone help ? Regards Giorgi Moniava

        G Offline
        G Offline
        Greg Rodgers
        wrote on last edited by
        #3

        use: AfxBeginThread(&MyThreadProc, (LPVOID)this, THREAD_PRIORITY_NORMAL); inside MyThreadProc you can add the code: CtestDlg *pTestDlg = (CtestDlg *)pParam; ... this will allow you to access any CtestDlg members.

        L 1 Reply Last reply
        0
        • G Greg Rodgers

          use: AfxBeginThread(&MyThreadProc, (LPVOID)this, THREAD_PRIORITY_NORMAL); inside MyThreadProc you can add the code: CtestDlg *pTestDlg = (CtestDlg *)pParam; ... this will allow you to access any CtestDlg members.

          L Offline
          L Offline
          Lost User
          wrote on last edited by
          #4

          Thanks Greg for you attention , but when i type : AfxBeginThread(&MyThreadProc,(LPVOID)this,0); i get an error : c:\..\: error C2276: '&' : illegal operation on bound member function expression Regards m0n0

          A 1 Reply Last reply
          0
          • L Lost User

            Thanks Greg for you attention , but when i type : AfxBeginThread(&MyThreadProc,(LPVOID)this,0); i get an error : c:\..\: error C2276: '&' : illegal operation on bound member function expression Regards m0n0

            A Offline
            A Offline
            Anthony_Yio
            wrote on last edited by
            #5

            Your MyThreadProc need to be static. And you only need to call like AfxBeginThread(MyThreadProc,(LPVOID)this,0); E.g CWinThread* pThread = AfxBeginThread (ThreadFunc, lpVoid, THREAD_PRIORITY_NORMAL, 0, CREATE_SUSPENDED); ASSERT (NULL != pThread); pThread->m_bAutoDelete = FALSE; pThread->ResumeThread (); By the way, make sure you protect the variables that you are accessing in the 'this ' in the thread by using those synchronization classes like CMutex, Interlock functions and etc. Sonork 100.41263:Anthony_Yio

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups