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 arguments to a worker thread function

Passing arguments to a worker thread function

Scheduled Pinned Locked Moved C / C++ / MFC
c++helptutorial
3 Posts 3 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.
  • G Offline
    G Offline
    gecool
    wrote on last edited by
    #1

    Hi everyone:->. I need to pass some arguments to a worker thread function (VC++), but i don't know how to do that ... the MSDN says : UINT MyControllingFunction( LPVOID pParam ), but I need to pass to MyControllingFunction other parameters too. If anyone can help, please do it.:)

    C T 2 Replies Last reply
    0
    • G gecool

      Hi everyone:->. I need to pass some arguments to a worker thread function (VC++), but i don't know how to do that ... the MSDN says : UINT MyControllingFunction( LPVOID pParam ), but I need to pass to MyControllingFunction other parameters too. If anyone can help, please do it.:)

      C Offline
      C Offline
      Chris Meech
      wrote on last edited by
      #2

      The LPVOID pParam should be set to point to a structure that contains all of the parameters that you wish to pass. Is this what you need? :) Chris Meech I am Canadian. [heard in a local bar] Gently arching his fishing rod back he moves the tip forward in a gentle arch releasing the line.... kersplunk [Doug Goulden] Nice sig! [Tim Deveaux on Matt Newman's sig with a quote from me]

      1 Reply Last reply
      0
      • G gecool

        Hi everyone:->. I need to pass some arguments to a worker thread function (VC++), but i don't know how to do that ... the MSDN says : UINT MyControllingFunction( LPVOID pParam ), but I need to pass to MyControllingFunction other parameters too. If anyone can help, please do it.:)

        T Offline
        T Offline
        ThatsAlok
        wrote on last edited by
        #3

        I demonstrate by passing your Class pointer to your Worker thread. Let your class be CMyClass and Worker thread function something like this

        [vccode]
        // Thread function
        UINT MyControllingFunction( LPVOID pParam );

        // Class
        void CMyClass::StartThread();
        {
        AfxBeginThread(&MyControllingFunction,(LPVOID)this);

        }

        // Actual Defination of Worker Thread
        UINT MyControllingFunction( LPVOID pParam )
        {
        CMyClass *pMainClass=(CMyClass*)pParam;
        //do something with pMainClass.......

        //end thread
        return 0;
        }


        [Vote One Here, Complete my Survey....] Alok Gupta
        visit me at http://www.thisisalok.tk          "I Think Believe this Will Help"

        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