getDoc() function crash wenn im debug mode
-
hi,
ich hab ne getDoc funktion mit der ich aus allen winkeln meiner app auf mein document zugreifen kann. leider crashed die funktion im debug mode. die funktion ist hauptsächlich aus der dokumentation von microsoft:
CXXXXXDoc* CXXXXXDoc::GetDoc() { CFrameWnd * pFrame = (CFrameWnd *)(AfxGetApp()->m_pMainWnd); if(pFrame) if(pFrame->GetActiveDocument() != NULL){ return (CXXXXDoc *) pFrame->GetActiveDocument(); } else{ return NULL; } else return NULL; }// end get doc
und zwar crashed sie beim aufruf von GetActiveDocument, wobei in folgender Answeisung:
// should also be in the permanent or temporary handle map CHandleMap* pMap = afxMapHWND(); ASSERT(pMap != NULL);
(in der wincore.cpp)
ich kann aus meinem view heraus die funktion ausrufen, dann klappts auch. jedoch von überall anders nicht. (nur im debug mode)irgendwelche ideen?
marcello
-
ich hba noch den folgenden kommentar in der ASSERT funktion gefunden. sehr merkwürdiger spruch:
// Note: if either of the above asserts fire and you are
// writing a multithreaded application, it is likely that
// you have passed a C++ object from one thread to another
// and have used that object in a way that was not intended.
// (only simple inline wrapper functions should be used)
//
// In general, CWnd objects should be passed by HWND from
// one thread to another. The receiving thread can wrap
// the HWND with a CWnd object by using CWnd::FromHandle.
//
// It is dangerous to pass C++ objects from one thread to
// another, unless the objects are designed to be used in
// such a manner.seit wann "kann" ich kein C++ object zu einem anderen thread schicken? was fürn quatsch is das denn? Meinen die damit in wirklichkeit "threadsafe" ? ich hoffe doch wohl!
-
Als erstes wundert mich, dass du die funktion in DEM doc hast, auf das du zugreifen willst - ich fände den MainFrame besser gewählt (oder die App).
Ich habe so eine Funktion für meine Views, vielleicht hilft sie dir ja. Die funktioniert jedenfalls einwandfrei.
inline CBasisView* CMainFrame::GetActiveBasisView() const { CBasisView* pView = dynamic_cast<CBasisView*>(GetActiveView()); ASSERT(pView); return pView; }
-
hi,
wiegesagt hätt ich das auch net so gemacht, aber die lieben freunde von MS haben das so "empfohlen". ich guck mir mal deins an.
-
ich hab mal neu gepostet... jetzt wo ich die "Wurzel" des übels gesehen hab.