Threads, DLLS - Managed C++ & Nativ
-
Hallo erstmal,
hatte bereits im C++ Forum dieses Thema aufgrund anderer Probleme angesprochen, denke jedoch es ist hire sicherlich besser aufgehoben - da es VC++ / Managed C++ spezifisch ist.Programm-Aufbau:
Ich habe einmal den Hauptthread, der anhand bestimmter Ereignisse Sub-Threads erstellt. Ich benutze eine Bibliothek, die ich über LoadLibrary "BibCapture" dynamisch zum Projekt hinzulade (im Hauptthread!).
Die SubThreads greifen jeweils auf die "BibCapture" zu. Um eine Zugriffsüberschneidung zu verhintern verwende ich "CriticalSection".Ich benutze Managed C++, Nativ (CLR) + eine die dnamische Bibliothek (in C geschrieben!)
Zum Problem:
Grundlegend funktioniert es, Es gibt jedoch bestimmte Situation (Die ich nicht kenne), bei denen das Teil einfach ohne Grund crashed.
Am häufigsten passieren diese Cashes, wenn ich einen Thread beende! Der Programmabstutz ist immer genau beim Aufrufen der FUnktion "Capturetext()" von "BibCapture" (Aber nur selten!). Beide Threads scheinen wunderbar zu funktionieren, nur bei besitmmten anomalien nicht - das muss ich heruasbekommen:Hier ein wenig Code:
[..] BOOL CCaptureTools::CaptureTextFromBMP( char *bmp_filename, std::string *text ) { ::EnterCriticalSection( &m_csCapture ); Capture_save( bmp_filename, text ); ::LeaveCriticalSection( &m_csCapture ); return TRUE; } [..]
Hier cashed das Programm
[..] CThread::OnUpdate() { m_cCaptureTools.CaptureTextFromBMP([...]); } [..]
Die Debug-Informationen helfe mir leider auch nicht weiter. Ich glaube jedoch, das Problem könnte an der Konbination von ManagedC++ / Native / C liegen.
Debug:
HEAP[MyApp-Test.exe]: Invalid Address specified to RtlFreeHeap( 01200000, 1002D180 )
Windows has triggered a breakpoint in MyApp-Test.exe.This may be due to a corruption of the heap, and indicates a bug in MyApp-Test.exe or any of the DLLs it has loaded.
The output window may have more diagnostic information
Diese Nachricht bekomme ich auch: Hab mal danach gegoogelt und glaube das könnte eine Nachricht sein, mit der ich was anfangen kann.
error: managed EE does not understand expression's syntax
Hier der Call-Stack:
bibcapture.dll!10019c13() bibcapture.dll!10002460() bibcapture.dll!100050eb() bibcapture.dll!1000f507() bibcapture.dll!1000b69d() bibcapture.dll!10008a46() ntdll.dll!7c9368ad() bibcapture.dll!10019c25() bibcapture.dll!10002460() bibcapture.dll!100036ab() [Managed to Native Transition] >(CRASH) MyApp.exe!CThreadUtils::CaptureEvents([..] = 0x0361FB38) Line 705 + 0xec bytes C++ [Native to Managed Transition] [Managed to Native Transition] MyApp.exe!CThread::DoUpdate() Line 680 + 0x25 bytes C++ MyApp.exe!CThread::Run(void* lpParam = 0x00F7DFE0) Line 582 C++ kernel32.dll!7c80b683() [Native to Managed Transition] ntdll.dll!7c936abe() kernel32.dll!7c80b683() ntdll.dll!7c936abe()
ALso falls jemand irgendwelche Idee hat, bitte ich zu posten. Für euere Hilfe vielen Dank
-
Ich gehe von aus, dass es evt. an problemen mit der DLL hängt diese "Multi-Thread" fähig zu machen.
Evt. könnte es Probleme bei der Übergabe der Parameter geben (Stack!):
#define DLL_IMPORT __cdecl typedef Success (DLL_IMPORT *FUNC_CAPTURE_INIT)(); typedef Success (DLL_IMPORT *FUNC_CAPTURE)( CaptureSource&, CaptureDest&, CaptureDestFormat);
Möglicherweise gibt es probleme bei __cdecl?
-
PS:
Hab hier gerade eine weitere Debug-Info gefunden:Additional information: Attempted to read or write protected memory. This is often an indication that other memory is corrupt.