Zugriff auf document aus workthread
-
Hallo wie kann ich aus einem Thread auf das aktuelle Document zugreifen?
UINT CSipromTApp::MyDisplayThread(LPVOID pParam) { CSipromTDoc* pDoc = (CSipromTDoc*)(((CMainFrame*)AfxGetMainWnd())->GetActiveDocument()); ASSERT(pDoc); if(pDoc->GetDeviceType() == 1) { MyTH100Com->MeasurementCom(); } }An der Stelle GetActiveDocument bekomme ich eine Zugriffsverletzung.
-
Das Problem hatte ich auch schon mal. Probiers mal so:
CFrameWnd* pMain = (CFrameWnd*)AfxGetMainWnd(); CSipromTDoc* pDoc = (CSipromTDoc*)pMain->GetActiveDocument( );Bei mir gings damit. Ich hab da noch was gefunden. Schau mal hier.
-
Wenn man die Methode AfxGetMainWnd aus einem Thread ausrufen will, muss man aber ein wenig aufpassen afaik.
MSDN:
AfxGetMainWnd is called from the application's primary thread, it returns the application's main window according to the above rules. 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.Kannst Du nicht einfach einen Pointer an deinen Thread übergeben, der auf die entsprechenden Daten verweist?
-
Mr.Yellow schrieb:
Wenn man die Methode AfxGetMainWnd aus einem Thread ausrufen will, muss man aber ein wenig aufpassen afaik.
Du hast natürlich Recht. Da ist ja Threadfunktion, hatte ich irgendwie überlesen. Eingentlich kann man, wie du schon sagst, das außerhalb des Threads durchführen und diesen Pointer als Parameter übergeben.