Thursday, December 22, 2005

Your application crashes (fails to initialise) with Visual Studio 8.0 and wxWidgets DLLs

If you are using Visual Studio 8.0 and wxWidgets DLLs and your application crashes immediately after starting or cannot be initialised properly, here is the fix:

  1. Open the file $(WXWIN)\src\msw\main.cpp
  2. Search for the function 'DllMain'
  3. Remove the entire function
  4. Recompile wxWidgets DLLs
Background:

When you open the wxWidgets .dsp files with Visual Studio 8.0, the solution conversion wizard adds the preprocessor symbol _WINDLL to the solution. This symbol is not defined when you compile the DLLs with older Visual Studios (.NET or 2003). When it is defined, the function DllMain gets compiled and included. This is causing the crash.

4 comments:

Anonymous said...

There's actually a slightly better way (imo) to handle this.

In main.cpp change the line
#ifndef WXMAKINGDLL
to
#if !(defined WXMAKINGDLL || defined WXMAKINGDLL_CORE)

At least it works for me!

Hajo Kirchhoff of Lit Window Productions said...

Not really since main.cpp is also used by wxbase, so you might get into trouble again with console applications, afaik.

BTW, the wxwidgets-core devs have determined that DllMain has not been used and have removed it in cvs head.

Best regards

Hajo

Anonymous said...

Good to know!

Anonymous said...

Hi,

just for the record this "bug" triggers a nasty "Access Violation" if you try to use wxWidgets inside a .dll. This happens when calling wxEntry(), wxEntryStart() or wxInitialize().

I thought I should let you know because it might help some other user in the future, since it took me a while to figure it out.

Andrea.