O
Hallo Community,
ich arbeite mit Visual Studio 2008 Prof und wxWidgets Version 2.8.12.
Ich habe mir ein kleines Testprojekt entworfen, das eine DLL einbindet. Mit der erstellten Klasse eine Aktionen ausführt. Danach wird die Testklasse wieder gelöscht. Das funktioniert auch soweit.
Mein Problem liegt darin, das wenn ich das Programm beende wird das 'wxDynamicLibrary'-Object zerstöre. Ich erhalte dann anschließend wenn das Fenster(Frame) zerstört werden soll eine Speicherschutzverletzung in der 'window.cpp' Zeile 568.
Seltsamer weise passiert das ganze auch nur wenn ich die Funktion 'Login' ausführe. Die Funktion 'Login' macht nichts anders als sich über HTTP mit dem Server zu verbinden.
Hier mal mein Code:
// ..
// Header aus Header
#include <wx/dynlib.h>
// Header SRC
#include "CHttpClient.h"
#include "CDllClass.h"
BasicFrame::BasicFrame(const wxString &title, const int &xpos, const int &ypos, const int &width, const int &hight)
:wxFrame( 0, wxID_ANY, title, wxPoint(xpos,ypos), wxSize(width,hight) )
, dllHandle(0)
{
dllHandle = new wxDynamicLibrary();
dllHandle->Load(_T("U:\\wxWidgetsProgs\\Project1\\versuche\\Dll_Versuch\\bin\\Win32\\Debug\\dll\\MyDllName"));
if (!dllHandle->IsLoaded())
{
wxLogError(_T("DLL nicht geladen"));
delete dllHandle;
Close();
return;
}
wxDynamicLibraryDetailsArray myAr = dllHandle->ListLoaded();
if (!dllHandle->HasSymbol(_T("ClassCreateDLL")))
{
wxString errText(_("Can't load DLL."));
errText << _T(" ") << _("Classsymbol not found.");
wxLogError(errText);
delete dllHandle;
Close();
return;
}
typedef IDllClass* (*fpFunc)();
fpFunc theFunk = static_cast<fpFunc>(dllHandle->GetSymbol(_T("ClassCreateDLL")));
IDllClass* newDllClass = theFunk();
newDllClass->HttpSet(ClientGet()); // Http-Verbindung
newDllClass->IxSet(_T("ix-MYINDEX")); // Index-Server
newDllClass->FolderMaskIdSet(1); // Order-Mask-ID
if (!newDllClass->Login(_T("LoginName"), _T("PWD")))
{
wxLogError(_T("Kein Login"));
}
// Aufräumen
newDllClass->Logout();
IHttpClient* cDele(newDllClass->HttpGet());
delete cDele;
cDele = 0;
delete newDllClass;
newDllClass = 0;
}
BasicFrame::~BasicFrame()
{
if (dllHandle != 0)
{
// dllHandle->Unload(); // Auch wenn ich vorher Unload ausführe gleicher Fehler
delete dllHandle;
dllHandle = 0;
}
}
Mal noch den Bereich aus der 'window.cpp' in der mir der Speicherschutzfehler angezeigt wird:
// Destructor
wxWindowMSW::~wxWindowMSW()
{
m_isBeingDeleted = true;
#ifndef __WXUNIVERSAL__
// VS: make sure there's no wxFrame with last focus set to us:
for ( wxWindow *win = GetParent(); win; win = win->GetParent() )
{
wxTopLevelWindow *frame = wxDynamicCast(win, wxTopLevelWindow);
if ( frame )
{
if ( frame->GetLastFocus() == this )
{
frame->SetLastFocus(NULL);
}
// apparently sometimes we can end up with our grand parent
// pointing to us as well: this is surely a bug in focus handling
// code but it's not clear where it happens so for now just try to
// fix it here by not breaking out of the loop
//break;
}
}
#endif // __WXUNIVERSAL__
// VS: destroy children first and _then_ detach *this from its parent.
// If we did it the other way around, children wouldn't be able
// find their parent frame (see above).
DestroyChildren();
if ( m_hWnd )
{
// VZ: test temp removed to understand what really happens here
//if (::IsWindow(GetHwnd()))
{
// -->>>>>>> Hier gibt es die Zugriffsverletzung
if ( !::DestroyWindow(GetHwnd()) )
wxLogLastError(wxT("DestroyWindow"));
}
// remove hWnd <-> wxWindow association
wxRemoveHandleAssociation(this);
}
delete m_childrenDisabled;
}
Wie kann es sein das ich durch das einbinden einer DLL eine Speicherschutzverletzung beim schließen bzw. beenden des Programmes erhalte.
Wenn ich im D'tor auf das löschen des dllHandle per delete verzichte, besteht das Problem nicht. Was dann allerdings dazu führt das ich ein 'Speicherleck' angezeigt bekomme.
Vielen Dank für etweilige Lösungsvorschläge