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. Trouble passing a class pointer to AfxBeingThread

Trouble passing a class pointer to AfxBeingThread

Scheduled Pinned Locked Moved C / C++ / MFC
sysadmindebugginghelpquestion
2 Posts 2 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.
  • K Offline
    K Offline
    KnaveR777
    wrote on last edited by
    #1

    Hey all, Im having a problem with passing a var to a function via AfxBeginThread. It appears the function is being called properly, but my data, which is in the form of a pointer to one of my ServerData classes, appears corrupted in the eyes of the thread function (debugger shows data as it should be before call, inside thread function, everything is chaotic). This is the code the starts the thread (triggered by a CListView message): LPVOID ptr = (LPVOID)((ServerData)m_serversList[pNMIA->iItem]); ServerData* sdat = (ServerData*)ptr; // debugger shows sdat to be intact CWinThread* thread = AfxBeginThread(&queryServer, ptr); This is performed at the begining of my thread func: UINT queryServer(LPVOID pParam ){ ServerData* server = ((ServerData*)pParam); // the var server has bad data ... } ServerData's LPVOID cast operator is simply defined as: return this; Any ideas?

    M 1 Reply Last reply
    0
    • K KnaveR777

      Hey all, Im having a problem with passing a var to a function via AfxBeginThread. It appears the function is being called properly, but my data, which is in the form of a pointer to one of my ServerData classes, appears corrupted in the eyes of the thread function (debugger shows data as it should be before call, inside thread function, everything is chaotic). This is the code the starts the thread (triggered by a CListView message): LPVOID ptr = (LPVOID)((ServerData)m_serversList[pNMIA->iItem]); ServerData* sdat = (ServerData*)ptr; // debugger shows sdat to be intact CWinThread* thread = AfxBeginThread(&queryServer, ptr); This is performed at the begining of my thread func: UINT queryServer(LPVOID pParam ){ ServerData* server = ((ServerData*)pParam); // the var server has bad data ... } ServerData's LPVOID cast operator is simply defined as: return this; Any ideas?

      M Offline
      M Offline
      MailtoGops
      wrote on last edited by
      #2

      Hi KnaveD, I would like to interpret the following your statement.. LPVOID ptr = (LPVOID)((ServerData)m_serversList[pNMIA->iItem]); I can assume that m_serversList[pNMIA->iItem] returns the ServerData object from an array of m_serversList. If you look at your typecasting, it seems to be, it is returning a temporary object, which you are typecasting to a void. That object is not at all a pointer!!!! Solution --------- If I am not wrong, you can modify your code like this.. LPVOID ptr = (LPVOID)((ServerData*) &m_serversList[pNMIA->iItem]); ie to get the address of the array element.. " Action without vision is only passing time, Vision without action is merely day dreaming, But vision with action can change the world " - Words from Nelson Mandela Thanks & Regards, Gopalakrishnan

      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