Scott Hanselman

EnableVisualStyles strikes again...

September 18, 2003 Comment on this post [2] Posted in Web Services | XML | Bugs
Sponsored By

My friend Jeff Berkowitz got nailed by the EnableVisualStyles bug in WinForms 1.1 that causes a weird SEHException when calling ShowDialog().  Jeff and his team really push WinForms to the limit and he finds some crazy stuff, including a scary Resource Naming problem in VS.NET 2003.

CLRSpy, Jeff Key, and Adam Nathan to the rescue though.  Although Jeff had debugged the problem and figured it out himself, CLRSpy would see the as an error probe and break on it.

Adam suggests three possible workarounds:

  1. Disable the PInvoke Calling Convention Mismatch probe, or
  2. Uncheck "Break on Error Messages" in CLR SPY so you can ignore this message and not provoke the crash, or
  3. Use an XML manifest to enable XP themes, rather than using the EnableVisualStyles API.

Of course, using the manifest is the preferred method methinks.

About Scott

Scott Hanselman is a former professor, former Chief Architect in finance, now speaker, consultant, father, diabetic, and Microsoft employee. He is a failed stand-up comic, a cornrower, and a book author.

facebook twitter subscribe
About   Newsletter
Hosting By
Hosted in an Azure App Service
May 13, 2004 22:17
Scott,

Thank Goodness for you and your WebSite!

I have been pulling my hair out trying to fix a problem where the first ShowDialog() works fine, but the second causes SEHException.

I found and commented out EnableVisualStyles() and my problems went away.

Thanks! Please, keep up the good work!
January 31, 2006 17:32
I know this is an old post, but here is another solution (for VS 2003, I don't know if VS 2005 has the same issues or not)

'Turn on XP Theme support if it exists
If OSFeature.Feature.IsPresent(OSFeature.Themes) Then
Application.EnableVisualStyles()
Application.DoEvents()
End If


First, you check for the support. Then enable the visual styles... and IMMEDIATELY follow with a DoEvents. No problems yet!

Comments are closed.

Disclaimer: The opinions expressed herein are my own personal opinions and do not represent my employer's view in any way.