DLL using wxWidgets shared by multiple host components Topic is solved

Do you have a question about makefiles, a compiler or IDE you are using and need to know how to set it up for wxWidgets or why it doesn't compile but other IDE's do ? Post your questions here.
Post Reply
ErwinH
In need of some credit
In need of some credit
Posts: 4
Joined: Wed Aug 05, 2015 6:05 am

DLL using wxWidgets shared by multiple host components

Post by ErwinH »

Hi all,

I'm using wxWidgets 3.0.2 under win32 compiled with MinGW 4.7.2 and would like to make a DLL that uses wxWidgets (with or without GUI) and that can be loaded and used by multiple host components (other DLLs or EXEs using or not using wxWidgets). In order to minimize the file size of the overall application, I would like to use wxWidgets from a dynamic, monolithic build (DLL) in all components.

For this purpose, I used the sample code of samples\DLL. So far, I tested with two compoents: A parent EXE and a child DLL both using wxWidgets (same version 3.0.2). The following build/linking scenarios worked well:
- EXE with wx statically linked, DLL with wx statically linked (STAT/STAT)
- EXE with wx statically linked, DLL with wx dynamically linked (STAT/DYN)
- EXE with wx dynamically linked, DLL with wx statically linked (DYN/STAT)

What did not work, however was the scenario:
- EXE with wx dynamically linked, DLL with wx dynamically linked (DYN/DYN)
Compiling and linking did not show any errors or warnings. When I started the EXE, the GUI (contained in the parent EXE) was displayed well, but the application hangs silently when calling functions from the DLL, no error messages are shown. When inspecting with Dependency Walker, all seems fine.

Is it possible that the scenario DYN/DYN does not work with this sample DLL? Might I have to modify the code in order to make it work?
User avatar
doublemax
Moderator
Moderator
Posts: 19160
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: DLL using wxWidgets shared by multiple host components

Post by doublemax »

The "DLL" sample is very special, it uses a separate thread for wxWidgets and it's intended for situations where the main application does not use wxWidgets, but has its own event loop.
- EXE with wx statically linked, DLL with wx statically linked (STAT/STAT)
- EXE with wx statically linked, DLL with wx dynamically linked (STAT/DYN)
- EXE with wx dynamically linked, DLL with wx statically linked (DYN/STAT)
You do realize that even in these cases, you end up with two different, totally independent wxWidgets instances? These can not share data. E.g. you can't have a wxWindow pointer in the main application and pass it to a method in the DLL.

If the main exe and the dll shall be able to work with the same wxWidgets objects, both must link to wxWidgets dynamically. That's the only combination where they both use the same wxWidgets instance.
Use the source, Luke!
ErwinH
In need of some credit
In need of some credit
Posts: 4
Joined: Wed Aug 05, 2015 6:05 am

Re: DLL using wxWidgets shared by multiple host components

Post by ErwinH »

Yes indeed, if I do not call run_wx_gui_from_dll() and wx_dll_cleanup() from the main application, no separate thread for wxWidgets is created and the same wxWidgets instance is used in all components. This works perfect.

It's good to know that I can use the "DLL" sample for the case where the main application does not use wxWidgets.

Thank you for your quick response.
Post Reply