C语言中的注册回调函数_onexit()

来源:互联网 发布:c语言快速入门教程 编辑:程序博客网 时间:2024/06/01 22:42

_onexit(func)

在MFC就经常看到回调函数,想不到在C语言中也有。

函数功能:

注册一个退出回调函数。

返回值:

成功返回一个指针,否则返回NULL。

参数:

回调函数的指针。

例子:

#include <stdlib.h>#include <stdio.h>int fn1(void), fn2(void), fn3(void), fn4 (void);void 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;}

输出:

This is executed first.This is executed next


详细使用可以搜索MSDN。

一句话解释:

onXXX()基本都是消息处理函数。

0 0
原创粉丝点击