c语言模拟window系统调用回调函数的过程
2016-11-21 16:36
337 查看
#include <time.h> #include <iostream> using namespace std; int getTime() { return clock() / CLOCKS_PER_SEC; } void debug(int num)//回调函数,这个函数模拟处理windows的不同消息,相当于win32的窗口过程处理函数windowProc { switch (num) { case 1: cout << "this is the first one" << endl; break; case 2: cout << "this is the second one" << endl; break; case 3: cout << "this is the third one" << endl; break; default: cout << "this is the default one" << endl; break; } } typedef void(*PFCALLBACK)(int); //PFCALLBACK是类型名 int start(PFCALLBACK f)//f是变量名,函数指针 { srand(time(0)); int lastTime = 0; while (true) { int now = getTime(); if (now - lastTime ==1)//每隔一秒 { int num = rand() % 10;//产生0到10之间的数据 f(num); //调用回调函数 lastTime = now; } } } //为什么需要回调函数? //第一,start函数本身可能不是你自己写的,已经封装成了dll,根本无法在start函数内部调用你的debug()函数 //第二,采用回调函数可以使你的dll库更具有通用性,使用start函数的每个人可以写自己的debug函数 int main() { start(debug); } //模拟window系统调用回调函数的过程
相关文章推荐
- C语言中的回调函数调用过程以及函数指针使用
- c语言里面的调用显示系统时间的函数及实现过程是什么
- 《Linux内核分析》 week6作业-Linux内核fork()系统调用的创建过程
- Linux 系统调用过程
- linux open 系统调用过程
- (转)详解汇编系统调用过程(以printf为例)
- Linux系统调用过程
- windows系统调用int 2e处理过程
- C语言中进程与系统调用
- c语言==系统调用与库函数的区别(28)
- 系统服务的调用过程(SystemService)
- [RK3288][Android6.0] 系统重启调用过程小结
- printf_系统调用过程分析_write() putc() 函数实现
- 汇编语言系统调用过程
- 窥探 kernel --- 系统调用过程分析
- 【Linux】Linux添加系统调用以及内核编译过程
- WINDOWS系统调用 和 SYSENTER系统服务调用过程
- C语言的标准库和系统调用
- C语言IO和系统调用IO
- 系统调用的初始化过程与系统调用执行过程