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. What's wrong with this????

What's wrong with this????

Scheduled Pinned Locked Moved C / C++ / MFC
comhelpquestion
5 Posts 4 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.
  • T Offline
    T Offline
    Tom Wright
    wrote on last edited by
    #1

    I'm trying to create my threads, but when I go to compile this I get an error: void CLAMsgSwDlg::StartAllThreads() { int nCount = m_lClientConn.GetItemCount(); ThreadInfo *mythreadinfo = new ThreadInfo[nCount]; for (int i = 0; i < nCount; i++) { mythreadinfo[i].thdIPaddress = m_lClientConn.GetItemText(i, 0); mythreadinfo[i].thdPort = m_lClientConn.GetItemText(i, 1); //Start all threads here. CWinThread* pThread = new CWinThread[nCount]; pThread[i] = AfxBeginThread(myThreadFunc, &mythreadinfo[i]); //Save the handle to the thread HANDLE* hThread = new HANDLE[nCount]; hThread[i] = pThread->m_hThread; } } UINT CLAMsgSwDlg::myThreadFunc(LPVOID pParam) { m_sConnectSocket.SetParent(this); //if (OnCreate) //{ //} } Can some one tell me what I'm doing wrong here. i get an error "none of the 2 overloads can convert the first parameter" Thanks Tom Wright tawright915@yahoo.com

    D S 2 Replies Last reply
    0
    • T Tom Wright

      I'm trying to create my threads, but when I go to compile this I get an error: void CLAMsgSwDlg::StartAllThreads() { int nCount = m_lClientConn.GetItemCount(); ThreadInfo *mythreadinfo = new ThreadInfo[nCount]; for (int i = 0; i < nCount; i++) { mythreadinfo[i].thdIPaddress = m_lClientConn.GetItemText(i, 0); mythreadinfo[i].thdPort = m_lClientConn.GetItemText(i, 1); //Start all threads here. CWinThread* pThread = new CWinThread[nCount]; pThread[i] = AfxBeginThread(myThreadFunc, &mythreadinfo[i]); //Save the handle to the thread HANDLE* hThread = new HANDLE[nCount]; hThread[i] = pThread->m_hThread; } } UINT CLAMsgSwDlg::myThreadFunc(LPVOID pParam) { m_sConnectSocket.SetParent(this); //if (OnCreate) //{ //} } Can some one tell me what I'm doing wrong here. i get an error "none of the 2 overloads can convert the first parameter" Thanks Tom Wright tawright915@yahoo.com

      D Offline
      D Offline
      David Crow
      wrote on last edited by
      #2

      You did not indicate what line was in error so I can only assume it was the AfxBeginThread() statement. Yes? If so, myThreadFunc() should be a static member, or a non-class function.


      "Opinions are neither right nor wrong. I cannot change your opinion of me. I can, however, change what influences your opinion." - David Crow

      T 1 Reply Last reply
      0
      • D David Crow

        You did not indicate what line was in error so I can only assume it was the AfxBeginThread() statement. Yes? If so, myThreadFunc() should be a static member, or a non-class function.


        "Opinions are neither right nor wrong. I cannot change your opinion of me. I can, however, change what influences your opinion." - David Crow

        T Offline
        T Offline
        Tom Wright
        wrote on last edited by
        #3

        Thanks David, I saw that in another program that I wrote a while back. After I made the function static, I received another error. On the same call I get an error "operator =" function is not avaliable in CWinThread. In the MSDN is says that it returns a pointer to the newly created object. Did I not setup my pointer right? Thanks Tom Wright tawright915@yahoo.com

        A 1 Reply Last reply
        0
        • T Tom Wright

          Thanks David, I saw that in another program that I wrote a while back. After I made the function static, I received another error. On the same call I get an error "operator =" function is not avaliable in CWinThread. In the MSDN is says that it returns a pointer to the newly created object. Did I not setup my pointer right? Thanks Tom Wright tawright915@yahoo.com

          A Offline
          A Offline
          Antony M Kancidrowski
          wrote on last edited by
          #4

          OK, this may help you out. Firtly make the myThreadFunc static as David says. Then if you alter the parameter class/struct to hold a pointer to the CLAMsgSwDlg class you can call the non-static member function and therefore other member elements. Add the following to the ThreadInfo class/struct

          CLAMsgSwDlg* thdParent;

          Make the alterations in bold

          void CLAMsgSwDlg::StartAllThreads()
          {
          int nCount = m_lClientConn.GetItemCount();

          ThreadInfo *mythreadinfo = new ThreadInfo[nCount];
          for (int i = 0; i < nCount; i++)
          {
          mythreadinfo[i].thdIPaddress = m_lClientConn.GetItemText(i, 0);
          mythreadinfo[i].thdPort = m_lClientConn.GetItemText(i, 1);
          mythreadinfo[i].thdParent = this;

          //Start all threads here.
          CWinThread* pThread = new CWinThread[nCount];
          pThread[i] = AfxBeginThread(myThreadFunc, &mythreadinfo[i]);

          //Save the handle to the thread
          HANDLE* hThread = new HANDLE[nCount];
          hThread[i] = pThread->m_hThread;
          }
          }

          UINT CLAMsgSwDlg::myThreadFunc(LPVOID pParam)
          {
          **ThreadInfo *threadinfo = reinterpret_cast<ThreadInfo*>(pParam);
          ASSERT(theadinfo != NULL);

          threadinfo->thdParent->DoThreadStuff();**
          }

          **void CLAMsgSwDlg::DoThreadStuff()
          {
          m_sConnectSocket.SetParent(this);
          //if (OnCreate)
          //{

          //}**
          }

          Ant. I'm hard, yet soft.
          I'm coloured, yet clear.
          I'm fruity and sweet.
          I'm jelly, what am I? Muse on it further, I shall return!
          - David Walliams (Little Britain)

          1 Reply Last reply
          0
          • T Tom Wright

            I'm trying to create my threads, but when I go to compile this I get an error: void CLAMsgSwDlg::StartAllThreads() { int nCount = m_lClientConn.GetItemCount(); ThreadInfo *mythreadinfo = new ThreadInfo[nCount]; for (int i = 0; i < nCount; i++) { mythreadinfo[i].thdIPaddress = m_lClientConn.GetItemText(i, 0); mythreadinfo[i].thdPort = m_lClientConn.GetItemText(i, 1); //Start all threads here. CWinThread* pThread = new CWinThread[nCount]; pThread[i] = AfxBeginThread(myThreadFunc, &mythreadinfo[i]); //Save the handle to the thread HANDLE* hThread = new HANDLE[nCount]; hThread[i] = pThread->m_hThread; } } UINT CLAMsgSwDlg::myThreadFunc(LPVOID pParam) { m_sConnectSocket.SetParent(this); //if (OnCreate) //{ //} } Can some one tell me what I'm doing wrong here. i get an error "none of the 2 overloads can convert the first parameter" Thanks Tom Wright tawright915@yahoo.com

            S Offline
            S Offline
            Sujan Christo
            wrote on last edited by
            #5

            Hi, myThreadFunc function must have 2 be a global function. So you are using a worker thread.Have a look @ this link this will surely help you http://www.flounder.com/workerthreads.htm[^] Sujan

            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