Microsoft Knowledge Base Article
This article contents is Microsoft Copyrighted material.
©2005-©2007 Microsoft Corporation. All rights reserved.
Terms
of Use |
Trademarks
Article ID: 897298 - Last Review: December 6, 2006 - Revision: 2.3
You receive an "unhandled exception of type 'System.Runtime.InteropServices.SEHException'" error message when you call the Application.EnableVisualStyles method in Visual Basic 2005 or in Visual Basic .NET
In Microsoft Visual Basic 2005 and in Microsoft Visual Basic .NET, when you call the
Application.EnableVisualStyles method from the
Form_Load event or from any other event, you receive an error message that is similar to the following:
An unhandled exception of type 'System.Runtime.InteropServices.SEHException'
occurred in system.windows.forms.dll
Note This issue occurs when the following conditions are true:
- The event calls the Application.EnableVisualStyles method again.
- The event calls the Application.EnableVisualStyles method when a form loads or after a form loads.
To work around this issue, use one of the following methods:
- Reorganize your code so that you only call the EnableVisualStyles method one time before you load any form. The following code example illustrates how to organize your code:
Public Sub Main()
Application.EnableVisualStyles()
Application.Run(New frmMain) 'Note: The frmMain form is the first form to open.
End Sub
- Create and then add an XML manifest file as a resource that enables your application to use visual styles. To do this, follow these steps:
- Link to ComCtl32.lib, and then call the InitCommonControlsEx function.
- Add a file that is named YourApp.exe.manifest that has the XML manifest format to the source tree. The source tree must be similar to the following code example:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">
<assemblyIdentity
version="1.0.0.0"
processorArchitecture="X86"
name="CompanyName.ProductName.YourApplication"
type="win32"
/>
<description>Type your application description here.</description>
<dependency>
<dependentAssembly>
<assemblyIdentity
type="win32"
name="Microsoft.Windows.Common-Controls"
version="7.0.0.0"
processorArchitecture="X86"
publicKeyToken="6595b64144ccf1df"
language="*"
/>
</dependentAssembly>
</dependency>
</assembly> - Add the XML manifest to the resource file of your application by using the following code example:
CREATEPROCESS_MANIFEST_RESOURCE_ID RT_MANIFEST "YourApp.exe.manifest"
Note You must add this line of code on one line. Alternatively, you can put the XML manifest file in the same folder as the executable file of your application. The operating system loads the XML manifest from the file system. Then, the operating system examines the resource section of the executable file. The file system version takes precedence.
You may receive the same error message that is discussed in the "Symptoms" section when you use the
ShowDialog method to open a form. To work around this behavior, use the
Show method instead of the
ShowDialog method.
APPLIES TO
- Microsoft Visual Basic 2005
- Microsoft Visual Basic .NET 2003 Standard Edition
- Microsoft Visual Basic .NET 2002 Standard Edition
| kbvs2005swept kbvs2005applies kbprb KB897298 |
Community Feedback System
Very often, it takes hours to solve a problem. Very often, you've looked high
and low, and have tried a lot of solutions. When you finally found it, chances
are, it was because someone else helped you. Here's your chance to give back.
Use our community feedback tool to let others know what worked for you and what
didn't.
Please also understand that the community feedback system is not warranted to be
correct, it's simply a system that we've built to let people try and help each
other. If something in a feedback response doesn't make sense to you, or you're
not comfortable making changes that the feedback talks about (like registry
edits), please consult a professional.
Thank you for using kbAlertz.com Feedback System.
-- Scott Cate
|
BlackTiger
|
Reported as Irrelevant
|
| Written:
7/8/2005 12:54 PM |
|
|
(Optional) Name
(Optional)
Public URL Or Email
Comments
No
HTML -- Text Only Please