Creating a wxFrame in a DLL
Creating a wxFrame in a DLL
I am currently trying to create a wxFrame in a dll (in Windows). I can create the dll, however when I try to use the class (wxFrame) from the dll my application crashes. After a bit of debugging, I have found that the constructor of the class is not being called. Thus the application crashes when the object of the class is used. The frame works perfectly if I do not put it into a dll. Does any one have any idea as to why this would be happening?
- xaviou
- Super wx Problem Solver
- Posts: 437
- Joined: Mon Aug 21, 2006 3:18 pm
- Location: Annecy - France
- Contact:
Hello.
I recently made a small tuto for creating a dll plugin application: I first create the wxFrame in the exe, and add some wxpanels from one or more dll (a plugins system)
The tuto is in french, but perhaps it can help you
You can find it here :
http://www.wxdevelop.com/tuto=FAIRE_UNE ... id=20.html
I recently made a small tuto for creating a dll plugin application: I first create the wxFrame in the exe, and add some wxpanels from one or more dll (a plugins system)
The tuto is in french, but perhaps it can help you
You can find it here :
http://www.wxdevelop.com/tuto=FAIRE_UNE ... id=20.html
-
- In need of some credit
- Posts: 6
- Joined: Thu Jun 08, 2006 5:18 am
- Location: Guatemala, Central America
- Contact:
I'm gonna paste code that I don't remember where I found, but the last time somebody else wrote a link.
Something that I didn't know was the use of __cdecl, but WXIMPORT and WXEXPORT do all the job. If have compiled the DLL I think you have done the most difficult part. Maybe your problem is that you haven't compiled wxWindows as shared library.
header
cpp file:
Something that I didn't know was the use of __cdecl, but WXIMPORT and WXEXPORT do all the job. If have compiled the DLL I think you have done the most difficult part. Maybe your problem is that you haven't compiled wxWindows as shared library.
header
Code: Select all
#include <wx/app.h>
#include <wx/list.h>
#ifdef WXMAKINGDLL_GLOBAL
#define WXUSINGDLL_GLOBAL WXEXPORT
#else
#define WXUSINGDLL_GLOBAL WXIMPORT
#endif
//Application
class wxDLLGlobalApp : public wxApp
{
public:
bool OnInit();
};
bool WXUSINGDLL_GLOBAL xyzfunction(const wxString& parametro);
cpp file:
Code: Select all
// We use IMPLEMENT_APP_NO_MAIN so we can start the app from DllMain
// as we don't have a WinMain or main entry point
//
IMPLEMENT_APP_NO_MAIN(wxDLLGlobalApp)
bool wxDLLGlobalApp::OnInit()
{
return true;
}
BOOL APIENTRY DllMain( HANDLE hModule,
DWORD ul_reason_for_call,
LPVOID lpReserved
)
{
switch (ul_reason_for_call)
{
case DLL_PROCESS_ATTACH:
{
//use wxInitialize() if you don't want GUI instead of the following lines
wxSetInstance((HINSTANCE)hModule);
int argc = 0;
char **argv = NULL;
wxEntryStart(argc, argv);
if ( !wxTheApp || !wxTheApp->CallOnInit() )
return FALSE;
}
break;
case DLL_PROCESS_DETACH:
wxEntryCleanup(); //use wxUninitialize() if you don't want GUI
break;
case DLL_THREAD_ATTACH:
case DLL_THREAD_DETACH:
break;
}
return TRUE;
}
2.6.1, wxMSW, MinGW, Code::Blocks
- xaviou
- Super wx Problem Solver
- Posts: 437
- Joined: Mon Aug 21, 2006 3:18 pm
- Location: Annecy - France
- Contact:
Sharkie: Hello.
I'm sorry, but I made this "for fun". Programming isn't my job.
And the base idea used in this tuto is not mine : I juste found an example that I've simplified.
The original idea can be found here: http://bzzt.net/~wxwidgets/PluginExample.zip
If you've downloaded the source code of my example, you should open the workspace file with Code::Blocks.
Notice that the dll code doesn't have any exported function. It has only classes dynamically declared.
Each plugin is loaded from the exe file with the "wxPluginManager::LoadLibrary(.....)" function.
Doing this makes dynamic classes of the plugin being registered in the RTTI (the wxPluginManager is a non-documented class of wxWidgets).
When all the plugins are loaded, we browse the RTTI classes list, to look for each classes named "DllPlugin". An instance of each one is the created with the wxClassInfo::CreateObject() function, and placed in a global wxList.
When the wxFrame is created, it creates a wxNotebook, adds a first page to it, and adds a page for each plugin present in the list.
I hope this will help you. If not, ask again.
Regards
I'm sorry, but I made this "for fun". Programming isn't my job.
And the base idea used in this tuto is not mine : I juste found an example that I've simplified.
The original idea can be found here: http://bzzt.net/~wxwidgets/PluginExample.zip
If you've downloaded the source code of my example, you should open the workspace file with Code::Blocks.
Notice that the dll code doesn't have any exported function. It has only classes dynamically declared.
Each plugin is loaded from the exe file with the "wxPluginManager::LoadLibrary(.....)" function.
Doing this makes dynamic classes of the plugin being registered in the RTTI (the wxPluginManager is a non-documented class of wxWidgets).
When all the plugins are loaded, we browse the RTTI classes list, to look for each classes named "DllPlugin". An instance of each one is the created with the wxClassInfo::CreateObject() function, and placed in a global wxList.
When the wxFrame is created, it creates a wxNotebook, adds a first page to it, and adds a page for each plugin present in the list.
I hope this will help you. If not, ask again.
Regards
-
- Knows some wx things
- Posts: 35
- Joined: Sun Nov 12, 2006 4:54 am
sharkie:
Do you mean using the wxWidgets DLL instead static lib can solve the problem?
My problem is similar.
I create wxApp and wxMDIParentFrame in app, and create a wxMDIChildFrame(implementation of myself) while loading a DLL, and I use wxWidgets as a static lib.
I expose a CreateSubFrame function in the DLL, and invoke it sucessfully, but failed in wxMDIChildFrame constructor.
Thanks.
Do you mean using the wxWidgets DLL instead static lib can solve the problem?
My problem is similar.
I create wxApp and wxMDIParentFrame in app, and create a wxMDIChildFrame(implementation of myself) while loading a DLL, and I use wxWidgets as a static lib.
I expose a CreateSubFrame function in the DLL, and invoke it sucessfully, but failed in wxMDIChildFrame constructor.
Thanks.