On Thu, 8 Apr 2021 03:16:15 -0700 (PDT) Sohaib Imran wrote:
SI> I am a beginner in wxWidgets. I am using windows and visual studio for
SI> development of my applications. Recently I was asked to convert my .exe
SI> application to a dll so that another .exe can load it as a plugin.
Just a warning: this is usually not completely trivial to do,
independently of the problem with the resources, because you need to decide
who is running the main event loop, the application or the DLL.
SI> The application that I made had an icon and various buttons that had loaded
SI> bitmaps to them. All the bitmaps were set using resources.rc file where I
SI> declared all the bitmaps in resources like this
SI> application ICON "application.ico"
SI> button1 ICON "button1.bmp"
SI> and in my code where I set these
SI> The application loaded all the icons correctly in the .exe of the app. But
SI> when I converted my application to a dll (to be used as a plugin) all the
SI> icons were disappeared. My buttons did not load the bitmaps. My frame was
SI> icon less. In the host .exe the error message was
SI> Can't load bitmap 'button1.bmp' from resources! Check .rc file
SI> So my question is
SI> How can we include the resources in the dll so that when it is loaded as
SI> plugin from a different .exe it loads all the icons and bitmaps if any
You need to initialize wxWidgets correctly from the DLL, so that it uses
the DLL instance handle and not the application one. You seem to be
initializing it from the application instead and this is not going to work
for many other reasons unless the DLL and the application use exactly the
same wxWidgets version -- which is not something you can usually guarantee
for a plugin.
There are 2 solutions that work:
1. If the application doesn't use wxWidgets, the DLL can statically link
with its own copy of wxWidgets. It will initialize it using its own
instance handle from its DllMain().
2. If both the application and the DLL use wxWidgets, then you must use
the same wxWidgets DLL in both of them.
The first case is simpler, so if you can, try doing it like this.
TT-Solutions: wxWidgets consultancy and technical support