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. static function vc++

static function vc++

Scheduled Pinned Locked Moved C / C++ / MFC
helpc++collaboration
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.
  • M Offline
    M Offline
    mperlera
    wrote on last edited by
    #1

    :(Hello!, I have a problem with static function, to access to member variable at same dialog class, both the static function and member variable are class members. The problem begin when i try compile a program with a function in a AfxBeginThead instruction with errors. I solve that problem, using a static function, but now i can't access a data member variable, of the dialog class of my project. Please help me!!! Thank for your collaboration. greating. mperlera

    D D 2 Replies Last reply
    0
    • M mperlera

      :(Hello!, I have a problem with static function, to access to member variable at same dialog class, both the static function and member variable are class members. The problem begin when i try compile a program with a function in a AfxBeginThead instruction with errors. I solve that problem, using a static function, but now i can't access a data member variable, of the dialog class of my project. Please help me!!! Thank for your collaboration. greating. mperlera

      D Offline
      D Offline
      Dave Bryant
      wrote on last edited by
      #2

      Since static functions do not have an implicit 'this' pointer, you cannot access any member (non-static) functions or data from within the static function. However, AfxBeginThread() allows to provide a user-defined parameter to your static thread function. In this case, you can pass in the pointer to the dialog as the user-defined parameter, and then use that within your thread function to get at the members. Dave http://www.cloudsofheaven.org

      1 Reply Last reply
      0
      • M mperlera

        :(Hello!, I have a problem with static function, to access to member variable at same dialog class, both the static function and member variable are class members. The problem begin when i try compile a program with a function in a AfxBeginThead instruction with errors. I solve that problem, using a static function, but now i can't access a data member variable, of the dialog class of my project. Please help me!!! Thank for your collaboration. greating. mperlera

        D Offline
        D Offline
        Dean Goodman
        wrote on last edited by
        #3

        What you usually do is something like the following:

        UINT CMyClass::ThreadFunc(LPVOID p) //this is your static func
        {
        CMyClass* pMyClass = (CMyClass*)p;

        p->SomeNonStaticFunc(); //access non-static member functions
        p->DataMember = 0; //access non-static member data
        ...
        return 0; //return your thread exit code
        }

        void CMyClass::SomeFunc()
        {
        AfxBeginThread(ThreadFunc, this); //start your thread function
        }

        --Dean

        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