Bonjour,
Petit soucis rencontré deux fois, je poste donc ici.
Mon environnement :
- C::B 13.12 Mingw32-gcc TDM
- wxWidgets 3.0.2 (shared 0, monolythic 0)
- scilab 5.5.2 [optional]
L'idée c'est de jouer avec les DLL wxDynamicLibrary
J'ai rencontré un problème avex wxMessageBox deux fois, je suppose que ça vient de la déclaration de wxWidgets dans ma DLL.
Configuration du projet dll :
Au niveau de mes appels et exports :
Le header "interface" (appli principale et plugin)
Le Header de ma classe :
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 #ifndef PLUGINMATHS_INTERFACE_H #define PLUGINMATHS_INTERFACE_H // Include common Headers #include "wxStuff.h" #if defined(__WIN32__) #define IMPLEMENT_PLUGINMATHS(name) extern "C" __declspec(dllexport) PluginMaths* CreatePlugin() { return new name();}; #else #define IMPLEMENT_PLUGINMATHS(name) extern "C" PluginMaths* CreatePlugin() { return new name();}; #endif class PluginMaths : public wxEvtHandler { public: /* DEBUG */ virtual wxString HelloWorld()=0; virtual wxString HelloPlot()=0; /* MAIN */ virtual wxString Start()=0; virtual wxString Stop()=0; virtual wxString Execute(wxString myCmd)=0; virtual wxString Push(double* myDoublePtr, wxString myVar)=0; virtual wxString Pull(wxString myVar)=0; virtual wxString GetError()=0; private: wxString myRep; int CodeError; void* pvApiCtx; }; //define a function pointer type for convenience #ifndef __PLUGINMATHS_FUNCTION #define __PLUGINMATHS_FUNCTION typedef PluginMaths* ( *CreatePluginMaths_function)(); #endif //__PLUGINMATHS_FUNCTION #endif
La partie de code sur laquelle je bloque et qui met en relief le probleme :
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 #ifndef PLUGINMATHS_SCILAB_H #define PLUGINMATHS_SCILAB_H #include "PluginMaths_Interface.h" #include "wx/wx.h" #include <wx/dlimpexp.h> #include <wx/msw/private.h> /* SciLab */ // http://weihuang.blogs.rice.edu/tips-on-computing-tools/the-method-to-use-scilab-function-in-c-code/ #include "call_scilab.h" #include "api_scilab.h" #include "stack-c.h" #if defined(__WIN32__) #define C_EXPORT extern "C" __declspec(dllexport) #endif class PluginMaths_SciLab : public PluginMaths { public: /* DEBUG */ virtual wxString HelloWorld(); virtual wxString HelloPlot(); /* MAIN */ virtual wxString Start(); virtual wxString Stop(); virtual wxString Execute(wxString myCmd); virtual wxString Push(double* myDoublePtr, wxString myVar); virtual wxString Pull(wxString myVar); virtual wxString GetError(); private: wxString myRep; int CodeError; void* pvApiCtx; }; #endif // PLUGINMATHS_SCILAB_H
Le probleme :
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 #include "PluginMaths_SciLab.h" IMPLEMENT_PLUGINMATHS(PluginMaths_SciLab) /* ********************** Instance ***********************************************/ wxString PluginMaths_SciLab::Start() { wxString myRep = _T("Started"); wxMessageBox(_T("Hello")); //if ( StartScilab(NULL, NULL, NULL) == FALSE ) myRep << _T("\nError : StartScilab"); //if ( StartScilab(getenv("SCI"), NULL, NULL) == FALSE ) myRep = _T("\nError : StartScilab"); //else myRep = _T("\nScilab Started"); /*#ifndef _MSC_VER myRep << _T("\t not _MSC_VER"); #else myRep << _T("\t OK _MSC_VER"); #endif*/ return myRep; }
- ma dll compile et j'ai, à coté de l'exe de mon appli principale le .def (que je ne sais pas utiliser), le .dll (sachant que le appli principale à l'interface.h dans le projet).
- avec le wxMessageBox commenté, tout passe, je récupere mon "Started"
- avec le wxMessageBox non commenté : crash
- avec le wxMessageBox commenté et les appels à SciLab non commenté : "Failed to load shared library (Error 0 : l'opération a réussi)"
Je pense qu'une déclaration a été mal faite. Notamment coté wxWidgets (premier problème).
Je précise que dans un projet sandbox non dll, le wxMessageBox et les appels à SciLab sont ok.
Mais j'aimerais garder ça en dll pour des questions de maintenance...
Ai-je raté quelque chose dans la déclaration des mes lib externes ?
Ai-je raté quelque chose dans l'implémentation des methodes de ma dll ?
Pour le coté déclaration de SciLab dans mes options projet (non visible dans les print-screen qui viennent d'un autre plugin OK dès qu'on a pas de wxMessageBox), il faut voir là :
http://www.developpez.net/forums/d92...el-scilab-cpp/
Partager