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. Question about AfxBeginThread(...)

Question about AfxBeginThread(...)

Scheduled Pinned Locked Moved C / C++ / MFC
questionhelp
6 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.
  • A Offline
    A Offline
    altfell
    wrote on last edited by
    #1

    Hello! I need to have a thread that can modify a Form.. I tried passing a form pointer as a param, but AfxBeginThread(...,LPVOID) says it cannot convert from Form1 __gc* to LPVOID. And I cannot make a unmanaged structure that contains a Form*.. How can I overcome this problem? Alin Stoian

    H R M 3 Replies Last reply
    0
    • A altfell

      Hello! I need to have a thread that can modify a Form.. I tried passing a form pointer as a param, but AfxBeginThread(...,LPVOID) says it cannot convert from Form1 __gc* to LPVOID. And I cannot make a unmanaged structure that contains a Form*.. How can I overcome this problem? Alin Stoian

      H Offline
      H Offline
      Hamid Taebi
      wrote on last edited by
      #2

      try this please void CMyAnswer::RunThread() { CWinThread* m_Thread; m_Thread=AfxBeginThread ( MyThread, this,THREAD_PRIORITY_NORMAL,0,CREATE_SUSPENDED); if (m_Thread != NULL) m_Thread->ResumeThread(); } UINT MyThread( LPVOID pv ) { CMyAnswer* m_Answer = (CMyAnswer*) pv; m_Answer->Modify(); return 0; } void CMyAnswer::Modify() { }_**


      **_

      WhiteSky


      A 1 Reply Last reply
      0
      • A altfell

        Hello! I need to have a thread that can modify a Form.. I tried passing a form pointer as a param, but AfxBeginThread(...,LPVOID) says it cannot convert from Form1 __gc* to LPVOID. And I cannot make a unmanaged structure that contains a Form*.. How can I overcome this problem? Alin Stoian

        R Offline
        R Offline
        Ryan Binns
        wrote on last edited by
        #3

        If you're using managed objects, I recommend you use managed threads - delegates. It makes life a bit easier.

        Ryan

        "Punctuality is only a virtue for those who aren't smart enough to think of good excuses for being late" John Nichol "Point Of Impact"

        A 1 Reply Last reply
        0
        • H Hamid Taebi

          try this please void CMyAnswer::RunThread() { CWinThread* m_Thread; m_Thread=AfxBeginThread ( MyThread, this,THREAD_PRIORITY_NORMAL,0,CREATE_SUSPENDED); if (m_Thread != NULL) m_Thread->ResumeThread(); } UINT MyThread( LPVOID pv ) { CMyAnswer* m_Answer = (CMyAnswer*) pv; m_Answer->Modify(); return 0; } void CMyAnswer::Modify() { }_**


          **_

          WhiteSky


          A Offline
          A Offline
          altfell
          wrote on last edited by
          #4

          Thanx, I tried what you've recomended. The problomem still persists because I can't transform a managed pointer into a void one... maybe I missed something. Anyway, your code works perfectly when using unmanaged classes like CMyAnswer. Alin Stoian

          1 Reply Last reply
          0
          • R Ryan Binns

            If you're using managed objects, I recommend you use managed threads - delegates. It makes life a bit easier.

            Ryan

            "Punctuality is only a virtue for those who aren't smart enough to think of good excuses for being late" John Nichol "Point Of Impact"

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

            Yes, it is easier to use managed threads. Thanx, Alin Stoian

            1 Reply Last reply
            0
            • A altfell

              Hello! I need to have a thread that can modify a Form.. I tried passing a form pointer as a param, but AfxBeginThread(...,LPVOID) says it cannot convert from Form1 __gc* to LPVOID. And I cannot make a unmanaged structure that contains a Form*.. How can I overcome this problem? Alin Stoian

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

              You need to pin a managed object in order to get a raw pointer to it.

              --Mike-- Visual C++ MVP :cool: LINKS~! Ericahist | PimpFish | CP SearchBar v3.0 | C++ Forum FAQ

              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