3 out of 4 rated this helpful - Rate this topic

AddVectoredExceptionHandler function

Applies to: desktop apps only

Registers a vectored exception handler.

Syntax

PVOID WINAPI AddVectoredExceptionHandler(
  __in  ULONG FirstHandler,
  __in  PVECTORED_EXCEPTION_HANDLER VectoredHandler
);

Parameters

FirstHandler [in]

The order in which the handler should be called. If the parameter is nonzero, the handler is the first handler to be called. If the parameter is zero, the handler is the last handler to be called.

VectoredHandler [in]

A pointer to the handler to be called. For more information, see VectoredHandler.

Return value

If the function succeeds, the return value is a handle to the exception handler.

If the function fails, the return value is NULL.

Remarks

If the FirstHandler parameter is nonzero, the handler is the first handler to be called until a subsequent call to AddVectoredExceptionHandler is used to specify a different handler as the first handler.

If the VectoredHandler parameter points to a function in a DLL and that DLL is unloaded, the handler is still registered. This can lead to application errors.

To unregister the handler, use the RemoveVectoredExceptionHandler function.

To compile an application that uses this function, define the _WIN32_WINNT macro as 0x0500 or later. For more information, see Using the Windows Headers.

Examples

For an example, see Using a Vectored Exception Handler.

Requirements

Minimum supported client

Windows XP

Minimum supported server

Windows Server 2003

Header

WinBase.h (include Windows.h)

Library

Kernel32.lib

DLL

Kernel32.dll

See also

AddVectoredContinueHandler
RemoveVectoredExceptionHandler
VectoredHandler
Vectored Exception Handling

 

 

Send comments about this topic to Microsoft

Build date: 3/6/2012

Did you find this helpful?
(1500 characters remaining)
Community Content Add
Annotations FAQ
Clear the x86 direction flag at beginning of handler
A handler registered with AddVectoredExceptionHandler on the x86-32 and x86-64 platforms should clear the x86 "direction flag" at its beginning using the "cld" opcode. If an exception occurs while the direction flag is set, such as during a forward overlapping memmove(), the direction flag will remain on at the time the vectored handler is called. C compilers for Windows assume that the direction flag is clear at function call time, and things like inlined memset() calls will corrupt memory if the direction flag is set. Normal exception handlers with __try are not affected because the C runtime library clears the direction flag.
Don't run managed code from the VectoredExceptionHandler

If you install a VectoredExceptionHandler (VEH), make sure that it never runs managed code. (This is similar to the restriction that you can't run managed code in DllMain). The VEH is for native SEH exceptions, and not managed exceptions.  Do not use the VEH to interfere with managed exception processing.

See http://blogs.msdn.com/jmstall/archive/2006/05/24/avoid-vectored-exception-handler-managed-code.aspx for more details.

There's a discussion about this on the forums at http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=1495891&SiteID=1.