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. _beginthread and MFC

_beginthread and MFC

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

    Hello I need to access a member-function of my MFC-app via the _beginthread-function. _beginthread(pingthread,0,(void *) (szBuffer)); "pingthread" is void CMyAppDlg::pingthread(void* parameter) { ... } But _beginthread does not seem to accept MFC-member-functions. Any solution? thanks

    U L D 3 Replies Last reply
    0
    • L Lost User

      Hello I need to access a member-function of my MFC-app via the _beginthread-function. _beginthread(pingthread,0,(void *) (szBuffer)); "pingthread" is void CMyAppDlg::pingthread(void* parameter) { ... } But _beginthread does not seem to accept MFC-member-functions. Any solution? thanks

      U Offline
      U Offline
      Ulf Ohlen
      wrote on last edited by
      #2

      pingthread has to be a static member function

      1 Reply Last reply
      0
      • L Lost User

        Hello I need to access a member-function of my MFC-app via the _beginthread-function. _beginthread(pingthread,0,(void *) (szBuffer)); "pingthread" is void CMyAppDlg::pingthread(void* parameter) { ... } But _beginthread does not seem to accept MFC-member-functions. Any solution? thanks

        L Offline
        L Offline
        Li Lirong
        wrote on last edited by
        #3

        I would suggest you to read one of newcomer's articales: http://www.pgh.net/~newcomer/callbacks.htm ;) Lirong

        1 Reply Last reply
        0
        • L Lost User

          Hello I need to access a member-function of my MFC-app via the _beginthread-function. _beginthread(pingthread,0,(void *) (szBuffer)); "pingthread" is void CMyAppDlg::pingthread(void* parameter) { ... } But _beginthread does not seem to accept MFC-member-functions. Any solution? thanks

          D Offline
          D Offline
          D D de Kerf
          wrote on last edited by
          #4

          I'd do the following: 1) Create a global function : void ThePingThread(void * pDlg) { if (pDlg != NULL) { ( (CMyAppDlg *) pDlg)->PingThread() ); } } 2) ...calling the pingthread function in your thread void CMyAppDlg::pingthread() { pParameter = m_pParamter; // Do your pinging stuff! } 3) Start the trhead as follows: void CMyAppDlg::RunPingThread(void* pParameter) { m_pParameter = pParameter; _beginthread(ThePingThread, 0, this); } It works for me! Structured programming vs. chaotic mind boggling

          L 1 Reply Last reply
          0
          • D D D de Kerf

            I'd do the following: 1) Create a global function : void ThePingThread(void * pDlg) { if (pDlg != NULL) { ( (CMyAppDlg *) pDlg)->PingThread() ); } } 2) ...calling the pingthread function in your thread void CMyAppDlg::pingthread() { pParameter = m_pParamter; // Do your pinging stuff! } 3) Start the trhead as follows: void CMyAppDlg::RunPingThread(void* pParameter) { m_pParameter = pParameter; _beginthread(ThePingThread, 0, this); } It works for me! Structured programming vs. chaotic mind boggling

            L Offline
            L Offline
            Lost User
            wrote on last edited by
            #5

            When I try to compile the compiler reports an error in line: ( ((CServerListDlg*) pDlg )->pingthread() ); (translated from german :)) "pingthread" : No access to protected element, which has been declared in class "CServerListDlg"

            D 1 Reply Last reply
            0
            • L Lost User

              When I try to compile the compiler reports an error in line: ( ((CServerListDlg*) pDlg )->pingthread() ); (translated from german :)) "pingthread" : No access to protected element, which has been declared in class "CServerListDlg"

              D Offline
              D Offline
              D D de Kerf
              wrote on last edited by
              #6

              That's quite logical, because you have to make the pingThread function public. If it's protected, it's quite impossible for a global function to access it... Tell me if it worked for you! Structured programming vs. chaotic mind boggling

              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