Click here to Skip to main content
15,886,609 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have class and that's like this

class mySample
{
  Cobject * cloneNode;
  std::list<Cobject *>cloneList;

}

and parallel processing as following code.
But It only executes when there is only one cbobject.
if clonelist have two or more... OnPlay function doesn't work.

function OnPlay(bool status, const CString& str ){

   if(pDC==NULL){
       CMainFrame * pFrame = (CMainFrame*)AfxGetMainWnd();
       CChildFrame *pChild = (CChildFrame*)pFrame->GetActiveFrame();
       CButterFlyEditorView *pView = (CButterFlyEditorView*)pChild->GetActiveView();
   ...

}


VStudio says
pChild 0xccccccc{hWnd=???}
pFrame 0x00000000<null>
this 0x0984f...{hWnd=0x000000<null>}

Can you advise me?
thanks for your time.

What I have tried:

parallel_for_each(CloneList.begin(), CloneList.end(), [&](Cobject* cloneNode) {
    cloneNode->OnPlay(file_status, m_ PathName);
});
Posted
Updated 13-Nov-17 20:38pm

1 solution

The explanation is already in your post: pFrame 0x00000000

Reading the documentation is always a good idea. In the text of AfxGetMainWnd you may had read
"If the function is called from a secondary thread in the application, the function returns the main window associated with the thread that made the call."
And your created threads have NO main window.

You must make the needed values from the primary thread as input parameters of your threading function. Windows is an operating system as iOS too) that run primary in the main thread. So it is never a good idea to access system elements from other threads. This ALWAYS needs excellent implementation.
 
Share this answer
 
Comments
CPallini 14-Nov-17 4:09am    
5.
Chopin2001 14-Nov-17 9:42am    
thanks Kakrstenk!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900