##################dll.h##################
#pragma once
typedef void (*CALLBACK)(int );
typedef struct
handleCB
{
CALLBACK
t_fun;
}stCallBack;
static stCallBack sHandlerCallBack;
extern void
RegisterPrint(CALLBACK fun);
extern void StartPrint(int interval);
##################dll.cpp##################
#include "dll.h"
void RegisterPrint(CALLBACK fun)
{
sHandlerCallBack.t_fun = fun;
}
void StartPrint(int
interval)
{
for (int i=0; i<interval;
i++) (*sHandlerCallBack.t_fun)(i);
}
##################app.cpp##################
#include <stdio.h>
#include "dll.h"
void PrintHello(int i)
{
printf("[PrintHello]:
Hello-%d\n", i);
}
int main(int argc, char **argv)
{
RegisterPrint(&PrintHello);
StartPrint(5);
return 0;
}
回调函数的应用误区4(c/s OK版本回调小程序),布布扣,bubuko.com
原文地址:http://www.cnblogs.com/jacklikedogs/p/3748085.html