Disable the crash dialog in VB6 (Visual Basic 6) with SetErrorMode()
If you don't want your Visual Basic 6 application to display the standard crash dialog, you can disable it by setting the SEM_NOGPFAULTERRORBOX flag in the process error mode.
The simple-minded way is just to do
SetErrorMode(SEM_NOGPFAULTERRORBOX);
but this overwrites the previous error mode rather than augmenting it. In other words, you inadvertently turned off the other error modes!
Unfortunately, there is no GetErrorMode function, so you have to do a double-shuffle.
Dim rc as Long rc = SetErrorMode(SEM_NOGPFAULTERRORBOX); SetErrorMode(rc Or SEM_NOGPFAULTERRORBOX); It works perfectly with VB6 and is very useful if you have to call a buggy third-party component, or a user-provided plugin that you don't trust. You can set the error mode right before calling the buggy dll and setting it back immediatelly after.
Sample VB6 code that disables the crash dialog with SetErrorMode:
Private Sub Form_Load() Dim rc As Long rc = SetErrorMode(0) rc = SetErrorMode(rc Or SEM_NOGPFAULTERRORBOX) rc = SetUnhandledExceptionFilter(AddressOf UnhandledExceptionFilter) End Sub