_onexit, _onexit_m
注册将调用实例在退出时。
_onexit_t _onexit(
_onexit_t function
);
_onexit_t_m _onexit_m(
_onexit_t_m function
);
参数
- function
对要调用的函数的指针在退出。
返回值
_onexit 返回指向该功能,如果成功或 NULL ,如果没有存储函数指针的空间。
备注
_onexit 函数传递 (function) 的调用的地址功能,当程序通常时停止。 连续调用 _onexit 创建按 LIFO 函数的寄存器 (后进先出 (lifo)) 顺序执行。 函数传递给 _onexit 不能采用参数。
在以下情况下,当 _onexit 调用从 DLL 的内部实例时,移动到 _onexit 注册在卸载的 DLL 运行,以 DllMain 调用与 DLL_PROCESS_DETACH 之后。
_onexit 是 Microsoft 扩展。 对于 ANSI 可移植性,请使用 atexit。 函数的 _onexit_m 版本用于混合模式使用。
要求
实例 |
必需的头 |
---|---|
_onexit |
stdlib.h |
有关更多兼容性信息,请参见中介绍的 兼容性 。
示例
// crt_onexit.c
#include <stdlib.h>
#include <stdio.h>
/* Prototypes */
int fn1(void), fn2(void), fn3(void), fn4 (void);
int main( void )
{
_onexit( fn1 );
_onexit( fn2 );
_onexit( fn3 );
_onexit( fn4 );
printf( "This is executed first.\n" );
}
int fn1()
{
printf( "next.\n" );
return 0;
}
int fn2()
{
printf( "executed " );
return 0;
}
int fn3()
{
printf( "is " );
return 0;
}
int fn4()
{
printf( "This " );
return 0;
}
Output
This is executed first.
This is executed next.