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
c++helptutorialquestion
8 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.
  • B Offline
    B Offline
    Burl D
    wrote on last edited by
    #1

    Hi, I am new here and I am very impressed with the level of skill I have seen in the articles, so I am very hopefull that someone can tell me where I am going wrong. I have a Dialog based app. in the main dialog header file I have declared a function UINT Recieve(LPVOID pParam); In the cpp file I try to start a worker thread like this AfxBeginThread(Recieve); I get a compiler error error C2665: 'AfxBeginThread' : none of the 2 overloads can convert parameter 1 from type 'unsigned int (void *)' The documentation says The controlling function defines the thread. When this function is entered, the thread starts, and when it exits, the thread terminates. This function should have the following prototype: UINT MyControllingFunction( LPVOID pParam ); and my code follows the example exactly. Anyone konow where I am screwing up?

    A N T 3 Replies Last reply
    0
    • B Burl D

      Hi, I am new here and I am very impressed with the level of skill I have seen in the articles, so I am very hopefull that someone can tell me where I am going wrong. I have a Dialog based app. in the main dialog header file I have declared a function UINT Recieve(LPVOID pParam); In the cpp file I try to start a worker thread like this AfxBeginThread(Recieve); I get a compiler error error C2665: 'AfxBeginThread' : none of the 2 overloads can convert parameter 1 from type 'unsigned int (void *)' The documentation says The controlling function defines the thread. When this function is entered, the thread starts, and when it exits, the thread terminates. This function should have the following prototype: UINT MyControllingFunction( LPVOID pParam ); and my code follows the example exactly. Anyone konow where I am screwing up?

      A Offline
      A Offline
      Anonymous
      wrote on last edited by
      #2

      Does it give the type it is expecting? 9ball wrote: error C2665: 'AfxBeginThread' : none of the 2 overloads can convert parameter 1 from type 'unsigned int (void *)' to type ???

      B 1 Reply Last reply
      0
      • B Burl D

        Hi, I am new here and I am very impressed with the level of skill I have seen in the articles, so I am very hopefull that someone can tell me where I am going wrong. I have a Dialog based app. in the main dialog header file I have declared a function UINT Recieve(LPVOID pParam); In the cpp file I try to start a worker thread like this AfxBeginThread(Recieve); I get a compiler error error C2665: 'AfxBeginThread' : none of the 2 overloads can convert parameter 1 from type 'unsigned int (void *)' The documentation says The controlling function defines the thread. When this function is entered, the thread starts, and when it exits, the thread terminates. This function should have the following prototype: UINT MyControllingFunction( LPVOID pParam ); and my code follows the example exactly. Anyone konow where I am screwing up?

        N Offline
        N Offline
        Nitron
        wrote on last edited by
        #3

        AfxBeginThread requires 2 paramaters, a function pointer and an LPVOID which is usually a pointer to the instance of the class that calls the thread. Also, your thread function should be declared static as well. Then you would spawn the thread like:

        AfxBeginThread(Recieve, this);

        - Nitron


        "Those that say a task is impossible shouldn't interrupt the ones who are doing it." - Chinese Proverb

        1 Reply Last reply
        0
        • B Burl D

          Hi, I am new here and I am very impressed with the level of skill I have seen in the articles, so I am very hopefull that someone can tell me where I am going wrong. I have a Dialog based app. in the main dialog header file I have declared a function UINT Recieve(LPVOID pParam); In the cpp file I try to start a worker thread like this AfxBeginThread(Recieve); I get a compiler error error C2665: 'AfxBeginThread' : none of the 2 overloads can convert parameter 1 from type 'unsigned int (void *)' The documentation says The controlling function defines the thread. When this function is entered, the thread starts, and when it exits, the thread terminates. This function should have the following prototype: UINT MyControllingFunction( LPVOID pParam ); and my code follows the example exactly. Anyone konow where I am screwing up?

          T Offline
          T Offline
          Tom Archer
          wrote on last edited by
          #4

          I just tested your code by placing the Recieve function within a clas and get that exact error message. You need to define the function as static if you're going to use a member function as the first parameter of all instance functions is the this pointer. Cheers, Tom Archer Inside C#,
          Extending MFC Applications with the .NET Framework It's better to listen to others than to speak, because I already know what I'm going to say anyway. - friend of Jörgen Sigvardsson

          A 1 Reply Last reply
          0
          • A Anonymous

            Does it give the type it is expecting? 9ball wrote: error C2665: 'AfxBeginThread' : none of the 2 overloads can convert parameter 1 from type 'unsigned int (void *)' to type ???

            B Offline
            B Offline
            Burl D
            wrote on last edited by
            #5

            No. I copied the error message directly from the output window and put it in the message. I created the app with app wizard. these are the include files #include "afxwin.h" // MFC core and standard components #include "afxext.h" // MFC extensions #include "afxdisp.h" // MFC Automation classes #include "afxdtctl.h" // MFC support for Internet Explorer 4 Common Controls #include "winsock2.h" #include "process.h" I added winsock2.h and process.h, and I have no other classes.

            B 1 Reply Last reply
            0
            • B Burl D

              No. I copied the error message directly from the output window and put it in the message. I created the app with app wizard. these are the include files #include "afxwin.h" // MFC core and standard components #include "afxext.h" // MFC extensions #include "afxdisp.h" // MFC Automation classes #include "afxdtctl.h" // MFC support for Internet Explorer 4 Common Controls #include "winsock2.h" #include "process.h" I added winsock2.h and process.h, and I have no other classes.

              B Offline
              B Offline
              Burl D
              wrote on last edited by
              #6

              I declared Recieve as static and that did it, thanks a lot for the help, I knew I came to the right place :)

              1 Reply Last reply
              0
              • T Tom Archer

                I just tested your code by placing the Recieve function within a clas and get that exact error message. You need to define the function as static if you're going to use a member function as the first parameter of all instance functions is the this pointer. Cheers, Tom Archer Inside C#,
                Extending MFC Applications with the .NET Framework It's better to listen to others than to speak, because I already know what I'm going to say anyway. - friend of Jörgen Sigvardsson

                A Offline
                A Offline
                adonisv
                wrote on last edited by
                #7

                Although I don't totally understand how this works, here is a sample of the code that I'm using. // Declared in the header file. bool StartReminder(); static UINT ThreadForReminder(LPVOID pParam); // When a user presses the remind me button I spin my //thread. void CConstantReminderDlg::OnRemindMeButton() { // Semi-interesting code. if(!this->GetThreadIsSpinning()) this->SpinThread(); } } UINT CConstantReminderDlg::ThreadForReminder(LPVOID pParam) { UINT returnCode = 0; CConstantReminderDlg* pObject = (CConstantReminderDlg*)pParam; if (pObject == NULL) return 1; // if pObject is not valid pObject->StartReminder(); return 0; // thread completed successfully } void CConstantReminderDlg::SpinThread() { // Set the dialog member to indicate that the // thread is currently spinning. this->SetThreadIsSpinning(true); // Spin the thread. ::AfxBeginThread(ThreadForReminder,this); } // The user has requested the program begin and the thread // for reminder dialog has been spun. bool CConstantReminderDlg::StartReminder() { CEvent wakeUpTimer(false,false,"probeDroid",NULL); HANDLE hHandle = (HANDLE)wakeUpTimer; COleDateTime timeStart,timeNext; //COleDateTimeSpan spanElapsed; // Indicate that the user wants the program to //continue. this->SetUserWantsToQuit(false); // A bunch of other stuff... :-D

                T 1 Reply Last reply
                0
                • A adonisv

                  Although I don't totally understand how this works, here is a sample of the code that I'm using. // Declared in the header file. bool StartReminder(); static UINT ThreadForReminder(LPVOID pParam); // When a user presses the remind me button I spin my //thread. void CConstantReminderDlg::OnRemindMeButton() { // Semi-interesting code. if(!this->GetThreadIsSpinning()) this->SpinThread(); } } UINT CConstantReminderDlg::ThreadForReminder(LPVOID pParam) { UINT returnCode = 0; CConstantReminderDlg* pObject = (CConstantReminderDlg*)pParam; if (pObject == NULL) return 1; // if pObject is not valid pObject->StartReminder(); return 0; // thread completed successfully } void CConstantReminderDlg::SpinThread() { // Set the dialog member to indicate that the // thread is currently spinning. this->SetThreadIsSpinning(true); // Spin the thread. ::AfxBeginThread(ThreadForReminder,this); } // The user has requested the program begin and the thread // for reminder dialog has been spun. bool CConstantReminderDlg::StartReminder() { CEvent wakeUpTimer(false,false,"probeDroid",NULL); HANDLE hHandle = (HANDLE)wakeUpTimer; COleDateTime timeStart,timeNext; //COleDateTimeSpan spanElapsed; // Indicate that the user wants the program to //continue. this->SetUserWantsToQuit(false); // A bunch of other stuff... :-D

                  T Offline
                  T Offline
                  Tom Archer
                  wrote on last edited by
                  #8

                  Send me your email ([tarcher@mindspring.com](mailto:tarcher@mindspring.com?subject=[CodeProject] AfxBeginThread help)) and I'll send you a very simple example of using AfxBeginThread. You can then compare, discern what you're doing wrong and post what you find here for anyone else that runs into the same problem. Cheers, Tom Archer Inside C#,
                  Extending MFC Applications with the .NET Framework It's better to listen to others than to speak, because I already know what I'm going to say anyway. - friend of Jörgen Sigvardsson

                  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