Bonjour.
Après moult recherche, je n'ai pas pu trouver la solution au problème suivant.
Je voudrais déporter la création de fenêtre fille dans des DLL. Dan sun premier temps je crée un dll que je link en statique et qui exporte une classe créant un un Frame et un wxPanel fils. Ca marche super bien.
Là ou ça coince, c'est quand je créer un thread avec wxThread. Je ne sais pas pourquoi (mais je pense que cela vient du passage de l'instance d'execution entre l'exe et la DLL) mais ça plante. Je peux soit utiliser un wxThread dans l'exe, soit exporter des Widgets depuis la dll, mais pas les deux. La création de la fenêtre, et du thread se passe bien, mais dés que le système le dispatcheur de message de la fenêtre tourne en même temps que le thread l'application plante.
le code :
The DLL LibTest :
LibTest.h
LibTest.cpp
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31 #ifndef __LIB_EXPORT__ #define __LIB_EXPORT__ #ifdef LIB_EXPORTS #define LIB_API __declspec(dllexport) #else #define LIB_API __declspec(dllimport) #endif extern HINSTANCE hModuleInst; class wxDLLApp : public wxApp { bool OnInit(); DECLARE_EVENT_TABLE() }; class LIB_API LibExport { public: LibExport( ); virtual ~LibExport( ); wxFrame * CreateParent( ); wxWindow * CreateChild( wxWindow * wxParent); public : wxWindow * m_pWndParent; }; #endif //__LIB_EXPORT__
Now the application:
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82 #include "wx/wxprec.h" #ifndef WX_PRECOMP #include "wx/wx.h" #endif #include "wx/app.h" #include <windows.h> #include "LibExport.h" HINSTANCE hModuleInst = NULL; BEGIN_EVENT_TABLE(wxDLLApp, wxApp) END_EVENT_TABLE() IMPLEMENT_APP_NO_MAIN(wxDLLApp) BOOL APIENTRY DllMain( HANDLE hModule, DWORD ul_reason_for_call, LPVOID lpReserved ) { switch (ul_reason_for_call) { case DLL_PROCESS_ATTACH: { hModuleInst = (HINSTANCE)hModule; wxSetInstance( hModuleInst); int argc = 0; char **argv = NULL; wxEntryStart(argc, argv); if ( !wxTheApp || !wxTheApp->CallOnInit() ) return FALSE; } break; case DLL_THREAD_ATTACH: case DLL_THREAD_DETACH: case DLL_PROCESS_DETACH: wxEntryCleanup( ); break; } return TRUE; } bool wxDLLApp::OnInit() { return true; } LibExport::LibExport( ) { m_pWndParent = NULL; } LibExport::~LibExport( ) { } wxFrame * LibExport::CreateParent( ) { return new wxFrame( NULL, wxID_ANY, _T(""), wxPoint(0, 0), wxDefaultSize); } wxWindow * LibExport::CreateChild( wxWindow * wxParent) { wxSetInstance( hModuleInst); wxPanel * pPane = new wxPanel( wxParent, 10000, wxDefaultPosition, wxDefaultSize, wxSUNKEN_BORDER|wxTAB_TRAVERSAL ); if( pPane != NULL) { wxGridSizer* itemGridSizer16 = new wxGridSizer(1, 1, 0, 0); pPane->SetSizer(itemGridSizer16); wxStaticText* itemStaticText17 = new wxStaticText( pPane, wxID_STATIC, _("Static text"), wxDefaultPosition, wxDefaultSize, 0 ); itemGridSizer16->Add(itemStaticText17, 0, wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL|wxALL|wxADJUST_MINSIZE, 5); } return pPane; }
DocView.h
Docview.cpp
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28 #ifndef __DOCVIEWSAMPLEH__ #define __DOCVIEWSAMPLEH__ class ManagerThread : public wxThread { public: ManagerThread( void); ~ManagerThread( ); virtual void * Entry( ); public: bool m_isAlive; }; class MyApp: public wxApp { public: MyApp(void); bool OnInit(void); int OnExit(void); ManagerThread * pWorker; }; DECLARE_APP(MyApp) #endif
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71 #include "wx/wxprec.h" #ifndef WX_PRECOMP #include "wx/wx.h" #endif #include "docview.h" #include "LibExport.h" IMPLEMENT_APP(MyApp) MyApp::MyApp(void) { } bool MyApp::OnInit(void) { LibExport lib; //wxFrame * pFrame = (wxFrame *)lib.CreateParent( ); wxFrame * pFrame = new wxFrame( NULL, wxID_ANY, _T(""), wxPoint(0, 0), wxDefaultSize); if( pFrame != NULL) { wxPanel * pane = (wxPanel *)lib.CreateChild( (wxWindow *)pFrame); pFrame->Maximize( true); pFrame->Show( true); SetTopWindow( pFrame); pWorker = new ManagerThread( ); if( pWorker->Create() == wxTHREAD_NO_ERROR ) pWorker->Run( ); return true; } else return false; } int MyApp::OnExit(void) { if( pWorker) delete pWorker; return 0; } ManagerThread::ManagerThread( void ) : wxThread() { m_isAlive = false; } ManagerThread::~ManagerThread( ) { m_isAlive = false; } void * ManagerThread::Entry( ) { m_isAlive = true; while( m_isAlive) { wxThread::Sleep(100); }; return NULL; }
merci beaucoup de votre attention.
Partager