Membres inscrits :598
Membres en ligne : 0
Invités en ligne : 5


|
| Conversation : DLL wxWidgets Scilab |
berger (Nouveau membre)
Inscrit le : 21-05-2008
Messages: 6
Snippets: 0
Tutoriels: 0
Hors ligne |
J'ai écrit une DLL à partir de la page http://wiki.wxwidgets.org/Creating_A_DL … pplication
Chez moi l'application marche avec wxWidgets 2.9.0 et VisualC++ 9.0. Est ce que cela marche avec votre configuration?
Voilà ce que la donne :
Code wxWidgets:///////////////////////////////// /// DLLMAIN //////////////////////////////// // dllmain.cpp : Définit le point d'entrée pour l'application DLL. #include <windows.h> #include "minimalWX.h" HANDLE ThreadId; MyApp *monAppli=NULL; DWORD WINAPI ThreadProc(LPVOID lpParameter) { if (lpParameter) { Sleep(7000); return true; } int argc=0; char **argv=NULL; wxApp::SetInstance(monAppli=new MyApp()); wxEntryStart(argc,argv); MyApp *g=(MyApp*)monAppli; g->OnInit(); g->OnRun(); return true; } BOOL APIENTRY DllMain( HMODULE hModule, DWORD ul_reason_for_call, LPVOID lpReserved ) { switch (ul_reason_for_call) { case DLL_PROCESS_ATTACH: { } break; case DLL_THREAD_ATTACH: case DLL_THREAD_DETACH: case DLL_PROCESS_DETACH: wxEntryCleanup(); break; } return TRUE; } extern "C" MINIMALWX_API void TestScilabRun(void) { ThreadProc((void*)NULL); } extern "C" MINIMALWX_API void TestScilabThread(void) { monAppli = (MyApp *)NULL; ThreadId = CreateThread(NULL,0,ThreadProc,(void*)monAppli,0,NULL); } extern "C" MINIMALWX_API void DLLToto(HWND handle) { ThreadId = CreateThread(NULL,0,ThreadProc,(void*)monAppli,0,NULL); } ///////////////////////////////// /// FIN DE DLLMAIN ////////////////////////////////
Code wxWidgets: //////////////////////////////// //////// WXMINIMAL.cpp exemple de wxWidgets //////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////// // Name: minimal.cpp // Purpose: Minimal wxWidgets sample // Author: Julian Smart // Modified by: // Created: 04/01/98 // RCS-ID: $Id: minimal.cpp 43915 2006-12-11 09:33:34Z CE $ // Copyright: (c) Julian Smart // Licence: wxWindows licence ///////////////////////////////////////////////////////////////////////////// // ============================================================================ // declarations // ============================================================================ // ---------------------------------------------------------------------------- // headers // ---------------------------------------------------------------------------- // For compilers that support precompilation, includes "wx/wx.h". #include "MinimalWX.h" // ---------------------------------------------------------------------------- // private classes // ---------------------------------------------------------------------------- // Define a new frame type: this is going to be our main frame class MyFrame : public wxFrame { public: // ctor(s) MyFrame(const wxString& title); // event handlers (these functions should _not_ be virtual) void OnQuit(wxCommandEvent& event); void OnAbout(wxCommandEvent& event); private: // any class wishing to process wxWidgets events must use this macro DECLARE_EVENT_TABLE() }; // ---------------------------------------------------------------------------- // constants // ---------------------------------------------------------------------------- // IDs for the controls and the menu commands enum { // menu items Minimal_Quit = wxID_EXIT, // it is important for the id corresponding to the "About" command to have // this standard value as otherwise it won't be handled properly under Mac // (where it is special and put into the "Apple" menu) Minimal_About = wxID_ABOUT }; // ---------------------------------------------------------------------------- // event tables and other macros for wxWidgets // ---------------------------------------------------------------------------- // the event tables connect the wxWidgets events with the functions (event // handlers) which process them. It can be also done at run-time, but for the // simple menu events like this the static method is much simpler. BEGIN_EVENT_TABLE(MyFrame, wxFrame) EVT_MENU(Minimal_Quit, MyFrame::OnQuit) EVT_MENU(Minimal_About, MyFrame::OnAbout) END_EVENT_TABLE() // Create a new application object: this macro will allow wxWidgets to create // the application object during program execution (it's better than using a // static object for many reasons) and also implements the accessor function // wxGetApp() which will return the reference of the right type (i.e. MyApp and // not wxApp) // ============================================================================ // implementation // ============================================================================ // ---------------------------------------------------------------------------- // the application class // ---------------------------------------------------------------------------- // 'Main program' equivalent: the program execution "starts" here bool MyApp::OnInit() { // call the base class initialization method, currently it only parses a // few common command-line options but it could be do more in the future if ( !wxApp::OnInit() ) return false; // create the main application window MyFrame *frame = new MyFrame(_T("Minimal wxWidgets App")); // and show it (the frames, unlike simple controls, are not shown when // created initially) frame->Show(true); // success: wxApp::OnRun() will be called which will enter the main message // loop and the application will run. If we returned false here, the // application would exit immediately. return true; } // ---------------------------------------------------------------------------- // main frame // ---------------------------------------------------------------------------- // frame constructor MyFrame::MyFrame(const wxString& title) : wxFrame(NULL, wxID_ANY, title) { // set the frame icon SetIcon(wxICON(sample)); #if wxUSE_MENUS // create a menu bar wxMenu *fileMenu = new wxMenu; // the "About" item should be in the help menu wxMenu *helpMenu = new wxMenu; helpMenu->Append(Minimal_About, _T("&About...\tF1"), _T("Show about dialog")); fileMenu->Append(Minimal_Quit, _T("E&xit\tAlt-X"), _T("Quit this program")); // now append the freshly created menu to the menu bar... wxMenuBar *menuBar = new wxMenuBar(); menuBar->Append(fileMenu, _T("&File")); menuBar->Append(helpMenu, _T("&Help")); // ... and attach this menu bar to the frame SetMenuBar(menuBar); #endif // wxUSE_MENUS #if wxUSE_STATUSBAR // create a status bar just for fun (by default with 1 pane only) CreateStatusBar(2); SetStatusText(_T("Welcome to wxWidgets!")); #endif // wxUSE_STATUSBAR } // event handlers void MyFrame::OnQuit(wxCommandEvent& WXUNUSED(event)) { // true is to force the frame to close Close(true); } void MyFrame::OnAbout(wxCommandEvent& WXUNUSED(event)) { wxMessageBox(wxString::Format( _T("Welcome to %s!\n") _T("\n") _T("This is the minimal wxWidgets sample\n") _T("running under %s."), wxVERSION_STRING, wxGetOsDescription().c_str() ), _T("About wxWidgets minimal sample"), wxOK | wxICON_INFORMATION, this); } ///////////////////// //// FIN DE WXMIMINIMAL.CPP /////////////////////
Code wxWidgets: ////////// ////// wxMINIMAL.h /////////////// #ifdef MINIMALWX_EXPORTS #define MINIMALWX_API __declspec(dllexport) #else #define MINIMALWX_API __declspec(dllimport) #endif #include "wx/wxprec.h" extern "C" MINIMALWX_API void DLLToto(HWND); // Define a new application type, each program should derive a class from wxApp class MyApp : public wxApp { public: // override base class virtuals // ---------------------------- // this one is called on application startup and is a good place for the app // initialization (doing it here and not in the ctor allows to have an error // return: if OnInit() returns false, the application terminates) virtual bool OnInit(); }; /////////////// //// Fin De wxMinimal /////////////
le code d'appel de la dll est le suivant :
Code Cpp: ///////////// ///// CODE POUR APPELER DLL //////////// #include <iostream> #include <windows.h> typedef void (*DLLFunctionPtr) (HWND); typedef void (*DLLFunctionScilab) (void); using namespace std; int main(int argc, char **argv) { LPCWSTR dest2 = L"MinimalWX"; HMODULE hModule=LoadLibrary(dest2); if (!hModule) cout<<"Erreur "<<GetLastError()<<endl; DLLFunctionScilab pProc = (DLLFunctionScilab)GetProcAddress(hModule, "TestScilabRun"); (pProc)(); pProc = (DLLFunctionScilab)GetProcAddress(hModule, "TestScilabThread"); (pProc)(); Sleep(10000); return 0; } //////////////// ////// FIN De code //////////////////
| |
|
Xaviou (Administrateur)
Lieu: Annecy (74)
Inscrit le : 27-08-2007
Messages: 1147
Snippets: 23
Tutoriels: 6
Site web
Hors ligne |
Salut.
Ça marche pour moi avec wxWidgets-2.8.10 / Unicode / Dynamique / Multi-Libs (Ça affiche 2 fois la fenêtre, mais c'est apparemment ce qui est demandé par la fonction "main").
Testé également en mode Statique, et ça marche également
@+ Xav'
P.S: Je me suis permis d'éditer ton post pour ajouter les balises "code" afin que ça soit plus lisible.
Dernière modification par Xaviou (04-11-2009 16:15:26)
|
Le nouveau portail wxWidgets francophone : www.wxdev.fr Ben en fait, vous y êtes déjà...
|
berger (Nouveau membre)
Inscrit le : 21-05-2008
Messages: 6
Snippets: 0
Tutoriels: 0
Hors ligne |
Merci pour le test. Le premier appel se fait à l'aide d'un appel à une fonction et le second par l'appel d'une fonction lançant un thread. Donc le programme appelant la DLL peut continuer son travail pendant la classe wxwidgets vit sa vie...
P.S. Avec les balises c'est plus clair
| |
|
carreau (Nouveau membre)
Inscrit le : 10-12-2008
Messages: 1
Snippets: 0
Tutoriels: 0
Hors ligne |
bonjour,
Très interessé par votre exemple, je l'ai repris et il fonctionne avec ma configuration : wxWidgets2.8.10 & VC++9 & XP
Mais lorsque j'appelle la DLL à partir d'un exe wxWidgets par l'intermédiaire d'un événement - click de souris - là, cela marche moins bien ; notamment lorsque je lance plusieurs instances de la DLL, et que je fais appel à MessageBox, j'obtiens l'erreur suivante :
Code:assert "wxAssertFailure" failed in wxMessagedialog::ShowModal():Unexpected::MassageBox() return code
De surcroit, lorsque je réalise une fonction global personnelle qui appelle tout simplement un MessageBox, cela plante furieusement ...
Merci pour vos explications
| |
|
|