3
votes

I'm building a form using Microsoft Visual Studio 2010 32-bit Premium (Microsoft Visual Basic 2010). When I compile the code there aren't any errors, but whenever I click on the exit button it gives me this message:

Win32Exception was unhandled" "error creating window handle".

What is the reason for this error and how can it be fixed?

I did this code in the university's lab, and it worked fine. But when I run it at home, I'm getting this error.

Private Sub btnExit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)    Handles btnExit.Click
    If MsgBox("Are you sure you want to exit the program?", MsgBoxStyle.Exclamation + MsgBoxStyle.YesNo) Then
        End ' error creating window handle 
    End If
End Sub

I'm using Windows 8 64-bit and Microsoft Visual Studio 2010 32-bit Premium.

1
You do not call End to exit a program. It's Application.Exit or Me.Close! - OneFineDay
Why End would produce such a mysterious exception is far more interesting. It is a perfectly valid way to end a program. Just like Environment.Exit(), also doesn't work anymore. Too bad nobody is interested. - Hans Passant
@HansPassant for my entire developing career calling End has been explained to me as bad like on the evil side of bad. It closes the application without closing all message pumps properly. It does not allow for any calling code to clean up cleanly. It might work fine in some places, but hurt you in others. I was told it's just bad practice. - OneFineDay
@DonA - well, use Environment.Exit() then. What you would use in an event handler for AppDomain.UnhandledException for example. You show the error to the user, he clicks OK and it goes Kaboom! Twice no less. This is a rather critical Windows bug, it's pretty new. - Hans Passant
This problem was fixed on my machine by a Windows update on Aug 14th. - Hans Passant

1 Answers

1
votes

You do not call End to exit a program. It's Application.Exit or Me.Close!