Hi! I'm using wxWidgets 2.8.9, built with the default settings under Windows XP, VC9. And I have absolutely standard EXE with IMPLEMENT_APP like this:
#include <wx/wx.h>
#include <wx/image.h>
#include "MainFrame.h"
class MyMainApp: public wxApp {
public:
bool OnInit();
};
IMPLEMENT_APP(MyMainApp)
bool MyMainApp::OnInit()
{
wxInitAllImageHandlers();
wxFrame* frame_mainFrame = new MainFrame(NULL, wxID_ANY, wxEmptyString);
SetTopWindow(frame_mainFrame);
frame_mainFrame->Show();
return true;
}
The MainFrame is a wxFrame with a "HelloWorld" text. This works fine when everything is linked in the EXE. The problem is, I would like to reuse this MainFrame class in another application and therefore I would like to have it in a DLL, so I can use the DLL code from everywhere.
Because my DLL has different export macro than wxWidgets, I can't export any derived from wxFrame class outside my Dll, so I make a factory class, which simply has one static method create(), returning new MainFrame(NULL, wxID_ANY, wxEmptyString);
So far so good. I have now a DLL, containing the MainFrame class, and one more FrameFactory class. Only the FrameFactory class is exported from my DLL and I can create the MainFrame in the EXE, in the OnInit() method like this: wxFrame* frame_mainFrame = FrameFactory::create();
The problem is that the constructor of the base class wxFrame calls wxTopLevelWindowMSW::CreateFrame(...), where the macro wxTheApp is invoked. This wxTheApp macro is actually a call to wxApp::GetInstance(). I was surprised that my wxApp instance is NULL when MainFrame is not in the EXE.
Could somebody familiar with wxWidgets help me what am I doing wrong? I made several more expreriments and always wxTheApp is NULL when the code using this instance variable is used in a different module, than the one where macro IMPLEMENT_APP is called.