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. passing param to the thread function

passing param to the thread function

Scheduled Pinned Locked Moved C / C++ / MFC
helpquestion
7 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
    singersinger
    wrote on last edited by
    #1

    the problem is that i have a thread function UINT threadfun(LPVOID param) { CList list = (CList)param; } and i want to pass param to this function using AfxBeginThread AfxBeginThread(threadfun,(WPARAM)m_List); where "m_List" is from a type defined variable typedef CTypedPtrList CList; the compiler generate this error: 1- 'CList' : undeclared identifier 2- syntax error : missing ';' before identifier 'list' 3- 'list' : undeclared identifier i know he can not see this type "CList" inside the function but what is the solution of this , and how can i make it work thnx alot 4 ur time and concern.

    N D Z S 4 Replies Last reply
    0
    • S singersinger

      the problem is that i have a thread function UINT threadfun(LPVOID param) { CList list = (CList)param; } and i want to pass param to this function using AfxBeginThread AfxBeginThread(threadfun,(WPARAM)m_List); where "m_List" is from a type defined variable typedef CTypedPtrList CList; the compiler generate this error: 1- 'CList' : undeclared identifier 2- syntax error : missing ';' before identifier 'list' 3- 'list' : undeclared identifier i know he can not see this type "CList" inside the function but what is the solution of this , and how can i make it work thnx alot 4 ur time and concern.

      N Offline
      N Offline
      Nibu babu thomas
      wrote on last edited by
      #2

      Is this file included... #include <afxtempl.h>


      Nibu thomas A Developer Programming tips[^]  My site[^]

      S 1 Reply Last reply
      0
      • N Nibu babu thomas

        Is this file included... #include <afxtempl.h>


        Nibu thomas A Developer Programming tips[^]  My site[^]

        S Offline
        S Offline
        singersinger
        wrote on last edited by
        #3

        yes it is included, but as u know the thread function is not a part of the class so it can't see the headers so it don't know what is CList exactly is problem right ?? i also tried to make the variable static and access it inside the thread function but it come up with an unresolved external error F Y I, this time was working perfeclty in a member function of the class but with the thread function, i don't know the problem

        G 1 Reply Last reply
        0
        • S singersinger

          yes it is included, but as u know the thread function is not a part of the class so it can't see the headers so it don't know what is CList exactly is problem right ?? i also tried to make the variable static and access it inside the thread function but it come up with an unresolved external error F Y I, this time was working perfeclty in a member function of the class but with the thread function, i don't know the problem

          G Offline
          G Offline
          Galatei
          wrote on last edited by
          #4

          Hi, yes it is included, but as u know the thread function is not a part of the class so it can't see the headers so it don't know what is CList exactly is Make sure that can be parsed by precompiler when header with your thread function is processed. You can even add #include <afxtempl.h> statement directly before your thread function declaration, example:

          #include <afxtempl.h>
          void __stdcall YourThreadFunction(LPVOID param)
          {
          CList list = (CList)param;
          }

          Did you know that your thread function can also be a part of your class?

          #include <afxtempl.h>
          class tester {
          private:
          CList m_list;
          public:
          void TestMyThread() {
          CreateThread(...,...,YourThreadFunction,this,...,...)
          };
          static void YourThreadFunction(LPVOID param)
          {
          tester *p = (tester*)param;
          CList list1 = p->m_list;
          };
          };

          Regards

          1 Reply Last reply
          0
          • S singersinger

            the problem is that i have a thread function UINT threadfun(LPVOID param) { CList list = (CList)param; } and i want to pass param to this function using AfxBeginThread AfxBeginThread(threadfun,(WPARAM)m_List); where "m_List" is from a type defined variable typedef CTypedPtrList CList; the compiler generate this error: 1- 'CList' : undeclared identifier 2- syntax error : missing ';' before identifier 'list' 3- 'list' : undeclared identifier i know he can not see this type "CList" inside the function but what is the solution of this , and how can i make it work thnx alot 4 ur time and concern.

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

            singersinger wrote:

            typedef CTypedPtrList<CPtrList , tagPLAYLISTENTRY*> CList;

            CList is the name of an existing class. Choose another name.


            "Approved Workmen Are Not Ashamed" - 2 Timothy 2:15

            "Judge not by the eye but by the heart." - Native American Proverb

            1 Reply Last reply
            0
            • S singersinger

              the problem is that i have a thread function UINT threadfun(LPVOID param) { CList list = (CList)param; } and i want to pass param to this function using AfxBeginThread AfxBeginThread(threadfun,(WPARAM)m_List); where "m_List" is from a type defined variable typedef CTypedPtrList CList; the compiler generate this error: 1- 'CList' : undeclared identifier 2- syntax error : missing ';' before identifier 'list' 3- 'list' : undeclared identifier i know he can not see this type "CList" inside the function but what is the solution of this , and how can i make it work thnx alot 4 ur time and concern.

              Z Offline
              Z Offline
              Zac Howland
              wrote on last edited by
              #6

              singersinger wrote:

              UINT threadfun(LPVOID param) { CList list = (CList)param; }

              There are a few problems here. First, CList is an existing type name when you use MFC. Use a different name for that: typedef CTypedPtrList CMyList;. Second, CMyList will be a type, not a pointer. Use the reference operator to cast it to get a pointer to it: AfxBeginThread(threadfun, (WPARAM)&m_List); and the corresponding: UINT threadfun(LPVOID wParam) { CMyList* list = (CMyList*)wParam; ...} Finally, if your threadfun is declared in another file, make sure it has the afxtempl.h header included.

              If you decide to become a software engineer, you are signing up to have a 1/2" piece of silicon tell you exactly how stupid you really are for 8 hours a day, 5 days a week Zac

              1 Reply Last reply
              0
              • S singersinger

                the problem is that i have a thread function UINT threadfun(LPVOID param) { CList list = (CList)param; } and i want to pass param to this function using AfxBeginThread AfxBeginThread(threadfun,(WPARAM)m_List); where "m_List" is from a type defined variable typedef CTypedPtrList CList; the compiler generate this error: 1- 'CList' : undeclared identifier 2- syntax error : missing ';' before identifier 'list' 3- 'list' : undeclared identifier i know he can not see this type "CList" inside the function but what is the solution of this , and how can i make it work thnx alot 4 ur time and concern.

                S Offline
                S Offline
                singersinger
                wrote on last edited by
                #7

                maybe i am posting the wrong words, so to keep it simple i have a function that causes the application to wait till it finishes it's work, so normally you would make it a thread function and call it using AfxBeginThread to let the application continue working after calling it am i right in this ?? if i am right, this function uses some member variables that are declared in the class but the thread function can't see the member variables of the class am i right ?? if i am, i want to pass this member variable to the thread function so that it could understand it and work with it "while this varibale not a rgular data type, it is a typedef from a combination of types" can anybody help me with this for any other information do not hesitate to reply thnx alot 4 ur time and concern.

                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