Skip to content

Latest commit

 

History

History
110 lines (83 loc) · 2.63 KB

onexit-onexit-m.md

File metadata and controls

110 lines (83 loc) · 2.63 KB
descriptiontitlems.dateapi_nameapi_locationapi_typetopic_typef1_keywordshelpviewer_keywordsms.assetid
Learn more about: _onexit, _onexit_m
_onexit, _onexit_m
11/04/2016
_onexit
_onexit_m
msvcrt.dll
msvcr80.dll
msvcr90.dll
msvcr100.dll
msvcr100_clr0400.dll
msvcr110.dll
msvcr110_clr0400.dll
msvcr120.dll
msvcr120_clr0400.dll
ucrtbase.dll
DLLExport
apiref
_onexit
onexit_m
onexit
_onexit_m
onexit function
registry, registering exit routines
_onexit_m function
onexit_m function
_onexit function
registering exit routines
registering to be called on exit
45743298-0e2f-46cf-966d-1ca44babb443

_onexit, _onexit_m

Registers a routine to be called at exit time.

Syntax

_onexit_t_onexit( _onexit_tfunction ); _onexit_t_m_onexit_m( _onexit_t_mfunction );

Parameters

function
Pointer to a function to be called at exit.

Return value

_onexit returns a pointer to the function if successful or NULL if there's no space to store the function pointer.

Remarks

The _onexit function is passed the address of a function (function) to be called when the program terminates normally. Successive calls to _onexit create a register of functions that are executed in LIFO (last-in-first-out) order. The functions passed to _onexit can't take parameters.

In the case when _onexit is called from within a DLL, routines registered with _onexit run when the DLL is unloaded, after DllMain is called with DLL_PROCESS_DETACH.

_onexit is a Microsoft extension. For ANSI portability, use atexit. The _onexit_m version of the function is for mixed mode use.

Requirements

RoutineRequired header
_onexit<stdlib.h>

For more compatibility information, see Compatibility.

Example

// crt_onexit.c#include<stdlib.h>#include<stdio.h>/* Prototypes */intfn1(void), fn2(void), fn3(void), fn4 (void); intmain( void ) { _onexit( fn1 ); _onexit( fn2 ); _onexit( fn3 ); _onexit( fn4 ); printf( "This is executed first.\n" ); } intfn1() { printf( "next.\n" ); return0; } intfn2() { printf( "executed " ); return0; } intfn3() { printf( "is " ); return0; } intfn4() { printf( "This " ); return0; }

Output

This is executed first. This is executed next. 

See also

Process and environment control
atexit
exit, _Exit, _exit
__dllonexit

close