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