SYMPTOMS
When you quit a Windows Form (WinForm) program that was
created in either Microsoft Visual Studio .NET (2002) or Microsoft Visual
Studio .NET (2003), you may receive one of the following error messages:
Unhandled exception at 0x77f87e4b (NTDLL.DLL) in
[ApplicationName]: 0xC0000005: Access violation reading location
0x00000324.
-or-
The instruction at "0x77f87e4b"
referenced memory at "0x00000324". The memory could not be "read". Click on OK
to terminate the program.
WORKAROUND
To work around this problem, use one of the following
methods.
Method 1: Change Your Display Settings
Change your display settings to run in a mode that is higher than
(8-bit) 256 color. To do this, follow these steps:
- Click Start, and then click
Control Panel.
- Click Appearance and Themes.
- Click Display.
- On the Settings tab, change the color
quality to a higher setting (for example, Highest (32
bit)).
- Click OK to close the Display
Properties dialog box.
Method 2: Run the Managed Code from an Unmanaged Loader
The loader handles process startup and shutdown and can load and
unload the Office Web Components and GDIPlus together in an orderly
fashion.
For more information, visit the following Microsoft Web site:
Method 3: Unload the Office Web Components Before Unloading GDIPlus
Close all open WinForms, close the Office Web Components, and then
close GDIPlus. To do this, add a static Main function to your .NET program, and
then add additional code such as the following:
Microsoft provides programming examples for illustration only, without warranty either expressed or implied. This includes, but is not limited to, the implied warranties of merchantability or fitness for a particular purpose. This article assumes that you are familiar with the programming language that is being demonstrated and with the tools that are used to create and to debug procedures. Microsoft support engineers can help explain the functionality of a particular procedure, but they will not modify these examples to provide added functionality or construct procedures to meet your specific requirements.
<DllImport("kernel32.dll", EntryPoint:="GetModuleHandle", _
SetLastError:=True, CharSet:=CharSet.Auto,
CallingConvention:=CallingConvention.StdCall)> _
Public Overloads Shared Function GetModuleHandle(ByVal sLibName As String) As IntPtr
End Function
<DllImport("kernel32.dll", EntryPoint:="FreeLibrary", _
SetLastError:=True, CallingConvention:=CallingConvention.StdCall)> _
Public Overloads Shared Function FreeLibrary(ByVal hMod As IntPtr) As Integer
End Function
<STAThread()> Public Overloads Shared Sub Main()
Dim hOwcHandle As IntPtr
System.Windows.Forms.Application.Run(New frmMainForm())
GC.Collect(2) ' Try to free if all instances were finalized already.
' If OWC is still around, then force unload it before exit.
hOwcHandle = GetModuleHandle("owc10.dll")
If Not hOwcHandle.Equals(IntPtr.Zero) Then FreeLibrary(hOwcHandle)
End Sub