Help!!! How to use wxWidgets in dll ? Topic is solved

If you are using the main C++ distribution of wxWidgets, Feel free to ask any question related to wxWidgets development here. This means questions regarding to C++ and wxWidgets, not compile problems.
Post Reply
hats
Experienced Solver
Experienced Solver
Posts: 70
Joined: Wed Sep 16, 2009 3:50 pm
Location: China
Contact:

Help!!! How to use wxWidgets in dll ?

Post by hats »

I want use wxWidgets in dll. I had seen the article http://wiki.wxwidgets.org/Creating_A_DL ... pplication
I use wxDec-C++ to create a new dll project. I copy the code and then compile but it don't work !! Could any body help me?? It is very important for me!! Thanks a lot!!
Romas
I live to help wx-kind
I live to help wx-kind
Posts: 176
Joined: Mon Jun 16, 2008 11:07 am
Location: Kaunas

Post by Romas »

What exactly doesn't work? Explain with more details...
Everything requires a line of code.
hats
Experienced Solver
Experienced Solver
Posts: 70
Joined: Wed Sep 16, 2009 3:50 pm
Location: China
Contact:

Post by hats »

OK.I use wxDev-C++ and create a new dll project. Then i copy the code that finded in the forum. When i compile it will be some errors.
It is the code ,Please help me!

Code: Select all

/* This is the dll.h */

#include <wx/wx.h>

#ifdef __WXMSW__
        #ifdef HELPER_EXPORTS
        #define HELPER_API __declspec(dllexport)
        #else
        #define HELPER_API __declspec(dllimport)
        #endif
#else // clever platforms do not need this
    #define HELPER_API
#endif


class HelperOption : public wxWindow
{
public:
    HelperOption(wxWindow* parent);
    ~HelperOption();
private:
    // any class wishing to process wxWidgets events must use this macro
    DECLARE_EVENT_TABLE()
};

HelperOption* options;


extern "C" HELPER_API LONG HelperProc(wxWindow* wnd); 

Code: Select all

/* The dllmain.cpp */
#include "dll.h"

BOOL APIENTRY DllMain( HANDLE hModule, DWORD ul_reason_for_call, LPVOID lpReserved)
{
    switch (ul_reason_for_call)
        {
        case DLL_PROCESS_ATTACH:
            {       
                int argc = 0;
                char **argv = NULL;
                if (!wxEntryStart(argc, argv) || !wxTheApp || !wxTheApp->CallOnInit() )
                        return FALSE;
            }
                        break;
                case DLL_THREAD_ATTACH:
                case DLL_THREAD_DETACH:
                        break;
                case DLL_PROCESS_DETACH:
                        wxEntryCleanup();
                        break;
    }
    return TRUE;
}

extern "C" HELPER_API LONG HelperProc(wxWindow* wnd)
{
    options = new HelperOption(wnd);
}

HelperOption::HelperOption(wxWindow* parent)
: wxWindow(parent, wxID_ANY, wxPoint(0,0), wxDefaultSize, wxBORDER_RAISED | wxTAB_TRAVERSAL)
{
   wxBoxSizer *topsizer = new wxBoxSizer( wxVERTICAL );

   topsizer->Add(new wxStaticText(this, wxID_ANY, "Helper Options", wxDefaultPosition, wxDefaultSize, wxALIGN_CENTRE));
   //... and so forth with the rest of the controls.
}
 

Attachments
The error information,Idont know how to do.
The error information,Idont know how to do.
error_information.jpg (26.8 KiB) Viewed 2695 times
Romas
I live to help wx-kind
I live to help wx-kind
Posts: 176
Joined: Mon Jun 16, 2008 11:07 am
Location: Kaunas

Post by Romas »

When showing compiler output, please give full output, not just blind image...

When compiling, add option -DHELPER_EXPORTS. And fix the line below:

Code: Select all

   topsizer->Add(new wxStaticText(this, wxID_ANY, wxString (wxT ("Helper Options")), wxDefaultPosition, wxDefaultSize, wxALIGN_CENTRE)); 
Everything requires a line of code.
hats
Experienced Solver
Experienced Solver
Posts: 70
Joined: Wed Sep 16, 2009 3:50 pm
Location: China
Contact:

Post by hats »

I still don't understand...May be there are some errors that in my project but i can't find them. Could you give me a simple wxDev-C++ project that use wxWidgets in dll ?
Romas
I live to help wx-kind
I live to help wx-kind
Posts: 176
Joined: Mon Jun 16, 2008 11:07 am
Location: Kaunas

Post by Romas »

Do not do "assisting answer" or "accept answer" on yourself...

I do not use dev-c++, but I use gnu compiler. Gnu does not have __delspec(import/export) it has different thing.

You need to describe your problem? What exactly does not work for you?
Everything requires a line of code.
hats
Experienced Solver
Experienced Solver
Posts: 70
Joined: Wed Sep 16, 2009 3:50 pm
Location: China
Contact:

Post by hats »

Error Information: wxSetInstance was not declared in this scope .
Is there a header file that need to be included?
hats
Experienced Solver
Experienced Solver
Posts: 70
Joined: Wed Sep 16, 2009 3:50 pm
Location: China
Contact:

Post by hats »

I follow this article:
http://forums.wxwidgets.org/viewtopic.php?p=5964#5964

I use mingw.The code need to include "wx/msw/private.h". DllMain function also need to be exported,else it doesn't work.The strings need to add "_T()".
And then it work!
Thanks a lot!
Post Reply