Segmentation fault when creating wxChoice from a DLL in Windows. 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
david_mtl
Earned a small fee
Earned a small fee
Posts: 20
Joined: Fri Jan 10, 2020 4:13 pm

Segmentation fault when creating wxChoice from a DLL in Windows.

Post 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,
User avatar
doublemax
Moderator
Moderator
Posts: 19158
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

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

Post 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.
Use the source, Luke!
david_mtl
Earned a small fee
Earned a small fee
Posts: 20
Joined: Fri Jan 10, 2020 4:13 pm

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

Post by david_mtl »

Alright, that makes sense. Thanks for the pointer.

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