Page 1 of 1

Segmentation fault when creating wxChoice from a DLL in Windows.

Posted: Fri Jan 24, 2020 7:23 pm
by david_mtl
Hi everyone,

I get a segmentation fault when instanciating a wxChoice in Windows from a DLL. It works well when I put the code directly into the host app. It also works from a shared library in linux, the problem is only in Windows.

When I debug it, the problem is located inside choice.cpp at the line 177

Code: Select all

// FIXME: Use better dummy window?
wxWindow* wnd = wxTheApp->GetTopWindow();
Going down inside GetTopWindow, I can see that GetInstance() from app.h returns 0x0, hence the segmentation fault.

Code: Select all

static wxAppConsole *GetInstance() { return ms_appInstance; }
About my config:
I use multiple DLL for wxWidgets.
wxWidgets`s version is 3.1.3
My custom dll uses a .DEF file so I haven't used any macro to define __declspec(dllexport)

Anyone got an idea?

Thanks,

Re: Segmentation fault when creating wxChoice from a DLL in Windows.

Posted: Fri Jan 24, 2020 8:52 pm
by doublemax
I can see that GetInstance() from app.h returns 0x0, hence the segmentation fault.
That would indicate that your DLL does not use the same wxWidgets instance as the main application.

Both the main application and your DLL must link to wxWidgets dynamically (as DLL) and they must use the same version. In both cases the preprocessor symbol WXUSINGDLL must be defined.

Re: Segmentation fault when creating wxChoice from a DLL in Windows.

Posted: Fri Jan 24, 2020 9:34 pm
by david_mtl
Alright, that makes sense. Thanks for the pointer.

EDIT: You were right, wxWidgets was built as a static lib.