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. UINT ThreadProc ( LPVOID param )

UINT ThreadProc ( LPVOID param )

Scheduled Pinned Locked Moved C / C++ / MFC
c++question
8 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.
  • S Offline
    S Offline
    susanne1
    wrote on last edited by
    #1

    Hello, i tried it the way you said, but it did not work , maybe i did something wrong, hier is the code: void CTestView::ThreadStart(CTestDoc* pDoc, CString strSel) { m_Thread_Sel_Start.SetEvent (); HWND hWnd = GetSafeHwnd(); m_strSelect = strSel; m_pDoc = pDoc;// i need to access the CTestDoc.cpp, i passed pDoc from the CTestDoc.cpp to the CTestView.cpp // and then assigend pDoc to m_pDoc which defined in the top of the CTestView.cpp AfxBeginThread(ThreadProc, this/*hWnd*/, THREAD_PRIORITY_NORMAL);// Hier i passed this to the ThreadProc function } UINT ThreadProc ( LPVOID param ) { (CTestView*)param-> // casting to CTestView did not work? return 0; }

    CPalliniC D M 3 Replies Last reply
    0
    • S susanne1

      Hello, i tried it the way you said, but it did not work , maybe i did something wrong, hier is the code: void CTestView::ThreadStart(CTestDoc* pDoc, CString strSel) { m_Thread_Sel_Start.SetEvent (); HWND hWnd = GetSafeHwnd(); m_strSelect = strSel; m_pDoc = pDoc;// i need to access the CTestDoc.cpp, i passed pDoc from the CTestDoc.cpp to the CTestView.cpp // and then assigend pDoc to m_pDoc which defined in the top of the CTestView.cpp AfxBeginThread(ThreadProc, this/*hWnd*/, THREAD_PRIORITY_NORMAL);// Hier i passed this to the ThreadProc function } UINT ThreadProc ( LPVOID param ) { (CTestView*)param-> // casting to CTestView did not work? return 0; }

      CPalliniC Offline
      CPalliniC Offline
      CPallini
      wrote on last edited by
      #2

      I encourage you to read this [^]. :)

      If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
      This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
      [My articles]

      In testa che avete, signor di Ceprano?

      S 1 Reply Last reply
      0
      • CPalliniC CPallini

        I encourage you to read this [^]. :)

        If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
        This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
        [My articles]

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

        okoay but i have an application crash hier: #ifdef _DEBUG void CTestView::AssertValid() const { CView::AssertValid(); // application crash } #ifndef _WIN32_WCE void CTestView::Dump(CDumpContext& dc) const { CView::Dump(dc); } #endif #endif

        CPalliniC 1 Reply Last reply
        0
        • S susanne1

          Hello, i tried it the way you said, but it did not work , maybe i did something wrong, hier is the code: void CTestView::ThreadStart(CTestDoc* pDoc, CString strSel) { m_Thread_Sel_Start.SetEvent (); HWND hWnd = GetSafeHwnd(); m_strSelect = strSel; m_pDoc = pDoc;// i need to access the CTestDoc.cpp, i passed pDoc from the CTestDoc.cpp to the CTestView.cpp // and then assigend pDoc to m_pDoc which defined in the top of the CTestView.cpp AfxBeginThread(ThreadProc, this/*hWnd*/, THREAD_PRIORITY_NORMAL);// Hier i passed this to the ThreadProc function } UINT ThreadProc ( LPVOID param ) { (CTestView*)param-> // casting to CTestView did not work? return 0; }

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

          Is there a question here that I'm failing to see? :confused:

          "Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown

          "Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons

          S 1 Reply Last reply
          0
          • D David Crow

            Is there a question here that I'm failing to see? :confused:

            "Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown

            "Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons

            S Offline
            S Offline
            susanne1
            wrote on last edited by
            #5

            The question is when i pass (this) instead of (hwnd) to the ThreadProc function i get a crash. The question is above.

            D 1 Reply Last reply
            0
            • S susanne1

              The question is when i pass (this) instead of (hwnd) to the ThreadProc function i get a crash. The question is above.

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

              How about formatting your code correctly AND using the <pre> tag?

              "Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown

              "Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons

              1 Reply Last reply
              0
              • S susanne1

                Hello, i tried it the way you said, but it did not work , maybe i did something wrong, hier is the code: void CTestView::ThreadStart(CTestDoc* pDoc, CString strSel) { m_Thread_Sel_Start.SetEvent (); HWND hWnd = GetSafeHwnd(); m_strSelect = strSel; m_pDoc = pDoc;// i need to access the CTestDoc.cpp, i passed pDoc from the CTestDoc.cpp to the CTestView.cpp // and then assigend pDoc to m_pDoc which defined in the top of the CTestView.cpp AfxBeginThread(ThreadProc, this/*hWnd*/, THREAD_PRIORITY_NORMAL);// Hier i passed this to the ThreadProc function } UINT ThreadProc ( LPVOID param ) { (CTestView*)param-> // casting to CTestView did not work? return 0; }

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

                -> has higher precedence than a cast, you need parens around the cast so it's evaluated first: ((CTestView*) param)->SomeMethod();

                --Mike-- Dunder-Mifflin, this is Pam.

                1 Reply Last reply
                0
                • S susanne1

                  okoay but i have an application crash hier: #ifdef _DEBUG void CTestView::AssertValid() const { CView::AssertValid(); // application crash } #ifndef _WIN32_WCE void CTestView::Dump(CDumpContext& dc) const { CView::Dump(dc); } #endif #endif

                  CPalliniC Offline
                  CPalliniC Offline
                  CPallini
                  wrote on last edited by
                  #8

                  You shouldn't use GUI stuff in worker threads. :)

                  If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
                  This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
                  [My articles]

                  In testa che avete, signor di Ceprano?

                  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