T-Rex / wxModularApp

Cross-Platform Modular Application (Main app + plugins) example for C++/wxWidgets
30 stars 17 forks source link

failed to register window class #1

Closed nonew closed 10 years ago

nonew commented 10 years ago

I have built successfully in Windows with wxWigets 3.0.1, but the following assert dialog popup when I debug wxModularHost application: ....\src\msw\window.cpp(3750): assert "wclass" failed in wxWindows::MSWCreate(): failed to register window class?

I found that the issue happen in the following function: void MainFrame::AddPagesFromGuiPlugins() { SampleModularCore * pluginManager = wxGetApp().GetPluginManager(); for(wxGuiPluginBaseList::Node * node = pluginManager->GetGuiPlugins().GetFirst(); node; node = node->GetNext()) { wxGuiPluginBase * plugin = node->GetData(); if(plugin) { wxWindow * page = plugin->CreatePanel(m_Notebook); <= gs_regClassesInfo become empty when run into this line, so that GetRegisteredClassName() will return null, even if "wxWindow" has already been registered. if(page) { m_Notebook->AddPage(page, plugin->GetName()); } } } }

Could you help to figure out the reason ? BTW, there are many C4275 warnings during compile, like this: warning C4275: non dll-interface class 'wxObject' used as base for dll-interface class 'wxGuiPluginBase' .... I am not sure if they are related or not. Thank you!

T-Rex commented 10 years ago

Hi. Which compiler are you using? Also plz show me the screenshot of your project settings page (C/C++ -> Code Generation). Remember, you need to use Shared build (DLL build) of wxWidgets with dynamic CRT, otherwise the project will not work. Ensure that path to wxWidgets libs contains libs\vc_dll (not libs\vc_libs) if you are using Visual Studio.

nonew commented 10 years ago

Hi T-Rex I'm using Visual Studio 2012 to compile the wxWidgets and wxModularApp projects. Here is the screenshot of my project settings page (C/C++ -> Code Generation). screenshot

I also installed Code::Blocks and use bundled GNU GCC compiler to compile the wxWidgets with Shared build (DLL build), and I checked that there are gcc_dll, vc_dll and vc_lib generated in my wxWidgets-3.0.1\lib path. I found that wxModularHost project was linking to vc_lib path, but I follow the exact steps in readme to build your projects. Can you tell me the wxWidgets Build Commands for Windows, I can only find for Linux and OS X.

PS: By using VS 2012 IDE, I can compile and run the 'dll' sample in wxWidgets without problems.

Thank you!

T-Rex commented 10 years ago

Try to temporarily remove or rename lib/vc_lib folder and then regenerate the project using CMake. CMake uses vc_lib if it finds it before vc_dll and this is not correct because only dll build supports modular architecture. If this does not help then let me know. Your project settings look fine for me. Also ensure that CMake module FindwxWidgets.cmake (inside CMake installation folder) has the rule for your version of wxwidgets, you can try to search for '30' in this file, there should be 4 places or so, where this suffix of wx lib file names is used.

nonew commented 10 years ago

Hi T-Rex It is like a magic, after I rename vc_lib and recompile your projects, no warnings and everything works fine!

One minor issue is that the following error message will popup when I debug wxModularHost: image

Firstly I copied wx dlls from vc_dll to build\bin\Debug path, then I found that I can solve it by adding PATH=$(WXWIN)\lib\vc_dll;%PATH% to my project settings page (Debugging -> Environment).

Thank you for your prompt help!

T-Rex commented 10 years ago

That's OK. Add vc_dll to PATH environment variable or copy dlls to the folder with your executable