Opened 5 years ago

Closed 5 years ago

#10203 closed defect (fixed)

crash when mouse enters window of app run from dll (FIX INCLUDED)

Reported by: StepanHrbek Owned by:
Priority: high Milestone:
Component: wxMSW Version: 2.8.9
Keywords: dll unload crash Cc:
Blocked By: Blocking:
Patch: no

Description

When mouse enters any window of wxWidgets app run from dll (not from exe, not from static library), comctl32.dll is loaded, unloaded and then called = crash.

FIX FOLLOWS:

Fix it by adding static in front of wxDynamicLibrary dllComCtl32(_T("comctl32.dll"), wxDL_VERBATIM); in src/msw/window.cpp line 5179. This prevents unload.

I described it (with sample code) in last paragraph of http://wiki.wxwidgets.org/Creating_A_DLL_Of_An_Application

Attachments (1)

setup.h download (43.7 KB) - added by StepanHrbek 5 years ago.
include/wx/msw/setup.h used when building wxWidgets

Download all attachments as: .zip

Change History (11)

comment:1 Changed 5 years ago by StepanHrbek

This problem was found and fix tested with wxWidgets configurations Debug DLL, Release DLL, 32bit code, 64bit code, Visual Studio 2008, Vista x64.

comment:2 Changed 5 years ago by oneeyeman

  • Status changed from new to infoneeded_new

Hi,
Can you describe what you need to replroduce the problem?
I am working with dialogs loaded from DLL without any problems...

Thank you.

comment:3 Changed 5 years ago by StepanHrbek

  • Status changed from infoneeded_new to new

Hi,

1) build wxWidgets 2.8.9 as DLL Release or DLL Debug, for win32 or x64 platform

2) build any other dynamic library, debug or release, with following code (it is reduction of my original program)

 class MyApp: public wxApp
 {
 public:
 	bool OnInit()
 	{
 		wxDialog* dlg = new wxDialog(NULL,-1,"Hello World From Library",wxDefaultPosition,wxDefaultSize,wxDEFAULT_DIALOG_STYLE,wxDialogNameStr);
 		dlg->Show();
 		return true;
 	}
 };
 
 static wxAppConsole *wxCreateApp()
 {
 	wxAppConsole::CheckBuildOptions(WX_BUILD_OPTIONS_SIGNATURE,"my app");
 	return new MyApp;
 }
 
 void RunApp()
 {
 	wxApp::SetInitializerFunction(wxCreateApp);
 	wxEntry(0,NULL);
 }

3) call RunApp

4) move mouse to window


When mouse enters window, comctl32.dll is loaded, unloaded and then called from src/msw/window.cpp line 5201. I see that it was unloaded in Visual Studio's debug output window. Crash comes immediately from accessing invalid address.

I used Visual Studio 2008 and Vista x64 SP1.

I disabled some wxWidgets features in setup.h.

Stepan

Changed 5 years ago by StepanHrbek

include/wx/msw/setup.h used when building wxWidgets

comment:4 Changed 5 years ago by vadz

  • Resolution set to duplicate
  • Status changed from new to closed

This is almost certainly the same as #9922. Do you use the manifest?

It would still be nice to avoid crashes if the "wrong" comctl32.dll gets loaded, I wonder if we could use GetModuleHandle("comctl32") instead of LoadLibrary("comctl32.dll") (which is what wxDynamicLibrary does) here.

But not unloading the DLL just masks the problem, surely nothing good is going to come from having 2 copies of comctl32.dll in the same process.

comment:5 Changed 5 years ago by VZ

(In [56863]) don't load comctl32.dll, just get the handle of the already loaded instance of it instead, this avoids accidentally loading 2 different versions of this DLL in the same process (see #10203)

comment:6 Changed 5 years ago by StepanHrbek

  • Resolution duplicate deleted
  • Status changed from closed to reopened

I was not using manifest. But manifest made no difference.

I included wx.rc in my library, verified that it bakes wx.manifest into my dll (so dll contains manifest with version="6.0.0.0" etc), verified that my exe uses correct dll, but wxWidgets dll still loads/unloads comctl32 5.82 and crashes. Log:

'MyApp.exe': Loaded 'C:\Windows\winsxs\x86_microsoft.windows.common-controls_6595b64144ccf1df_5.82.6001.18000_none_886786f450a74a05\comctl32.dll'
'MyApp.exe': Unloaded 'C:\Windows\winsxs\x86_microsoft.windows.common-controls_6595b64144ccf1df_5.82.6001.18000_none_886786f450a74a05\comctl32.dll'

"depends.exe myapp.exe" shows dependency on comctl32.dll 5.82 and 6.10

"depends.exe mylib.dll" shows dependency on comctl32.dll 5.82 and 6.10

Whole dependency tree of mylib.dll contains 1x 6.10 (right under wxmsw28_core_vc_custom.dll) and 4x 5.82 (deep under advapi32.dll)

comment:7 Changed 5 years ago by vadz

  • Status changed from reopened to infoneeded_new

Interesting, could you please test if the change of r56863 fixed this by chance? Thanks!

comment:8 Changed 5 years ago by StepanHrbek

  • Status changed from infoneeded_new to new

Joe Cocovich run into this crash, updated to svn head and he confirms that 2.9.0 does not crash when mouse enters window.

I had no time to modify my project to work with 2.9.0 yet, sorry :( (My workaround with "static" in 2.8.9 works fine so far.)

comment:9 Changed 5 years ago by vadz

  • Resolution set to port to stable
  • Status changed from new to portneeded

Ok, thanks, we need to backport the changes of r56863 and r57405 improving it to 2.8 branch now. If anybody has time to make (and test) a patch against 2.8 with these changes it would be very nice.

comment:10 Changed 5 years ago by VZ

  • Resolution changed from port to stable to fixed
  • Status changed from portneeded to closed

(In [58750]) don't load comctl32.dll, just get the handle of the already loaded instance of it instead [backport of r56863 and r57405 from trunk] (closes #10203)

Note: See TracTickets for help on using tickets.