这个函数应该怎么理解?
第一次见这么复杂的函数,实在找不到头绪了,那位能帮忙解决下这个问题?小弟在此拜谢!!NET_DVR_API BOOL NET_DVR_SetDVRMessCallBack(BOOL ( *fMessCallBack)(int lCommand,char *sDVRIP,char *pBuf,UINT32 dwBufLen));
功能:设置接收硬盘录像机(DVR)消息的回调函数(以IP 地址区分设备)
软件包中所有需主动上传的信息(异常除外)都通过 NET_DVR_SetDVRMessCallBack()函数设置的回调函数上传
fMessCallBack:消息回调函数,像硬盘录像机主动发起的请求;以及通过报警上传通道收到的报警信息,都通过此函数回调。
lCommand:消息的类型,定义如下:
#define COMM_ALARM 0x1100 (报警信息)
异常类型
#define EXCEPTION_EXCHANGE 0x8000 (用户交互时异常)
#define EXCEPTION_AUDIOEXCHANGE 0x8001 (语音对讲异常)
#define EXCEPTION_ALARM 0x8002 (报警异常)
#define EXCEPTION_PREVIEW 0x8003 (网络预览异常)
#define EXCEPTION_SERIAL 0x8004 (透明通道异常)
sDVRIP:服务器的IP地址
pBuf:存放信息的缓冲区,不同的类型分别指向不同的结构
dwBufLen:缓冲区的大小
返回值:TRUE表示成功,FALSE表示失败
我就不明白BOOL ( *fMessCallBack)这是个什么东西?函数的参数怎么这么用?BOOL ( *fMessCallBack)(int lCommand,char *sDVRIP,char *pBuf,UINT32 dwBufLen)
参数一般不就(A,B,C,...)这种形式的吗?这个函数怎么里边这么复杂是啥意思?
[此贴子已经被作者于2007-10-14 21:27:53编辑过]
----------------解决方案--------------------------------------------------------
它在程序中的应用是这样的,我还不明白红色部分的函数原型不是上边的NET_DVR_SetDVRMessCallBack吗?为什么到用的时候变成红色部分这样写的了?
uint32_t MessCallBack(int32_t lCommand, char *sDVRIP, char *pBuf, uint32_t dwBufLen)
{
int32_t lIndex = -1;
int i;
char timestamp[30] = {0};
char frontID[36] = {0};
//--------------------------网络异常时-------------------------------------------------------
if(lCommand < EXCEPTION_EXCHANGE) //EXCEPTION_EXCHANGE 0x8000 (探询设备时网络异常)
{
fprintf(stderr, "lCommand[%x], sDVRIP[%s], pBuf[%s], dwBufLen[%d]\n",
lCommand, sDVRIP, pBuf, dwBufLen);
#ifdef SDK_ALCATEL
if (lCommand == COMM_ALARM) { //COMM_ALARM 0x1100 报警信息
#ifdef ALCATEL_FRONTIDCFG
fprintf(stderr, "ALARM:FrontID:");
for (i=0;i<32;i++)
fprintf(stderr, "%d", *(pBuf+i));
fprintf(stderr, "\n\r");
fprintf(stderr, "ALARM:AlarmType:%d\n",
((LPNET_DVR_ALARMINFO)(pBuf+32))->dwAlarmType); //dwAlarmType 0-信号量报警,1-硬盘满,2-信号丢失,3-移动侦测,4-硬盘未格
式化,5-读写硬盘出错,6-遮挡报警
#ifdef SDK_ALCATEL_DX
if (((LPNET_DVR_ALARMINFO)(pBuf+32))->dwAlarmType == 0)
fprintf(stderr, "ALARM:AlarmStatus:%s\n",
((LPNET_DVR_ALARMINFO)(pBuf+32))->dwAlarmStatus ? //dwAlarmStatus 1-signal alarm occur 0-signal alarm stop *ONLY
significant when dwAlarmType=0*
"signal alarm occur" : "signal alarm stop");
fprintf(stderr, "ALARM:Alarm Code:");
for (i=0;i<6;i++) {
fprintf(stderr, "%d", ((LPNET_DVR_ALARMINFO)(pBuf+32))->alarmCode[i]);
}
fprintf(stderr, "\n\r");
#endif
#else
fprintf(stderr, "ALARM:AlarmType:%d\n",
((LPNET_DVR_ALARMINFO)pBuf)->dwAlarmType);
#ifdef SDK_ALCATEL_DX
if (((LPNET_DVR_ALARMINFO)pBuf)->dwAlarmType == 0)
fprintf(stderr, "ALARM:AlarmStatus:%s\n",
((LPNET_DVR_ALARMINFO)pBuf)->dwAlarmStatus ?
"signal alarm occur" : "signal alarm stop");
fprintf(stderr, "ALARM:Alarm Code:");
for (i=0;i<6;i++) {
fprintf(stderr, "%d", ((LPNET_DVR_ALARMINFO)pBuf)->alarmCode[i]);
}
fprintf(stderr, "\n\r");
#endif
#endif
}
#ifdef SDK_ALCATEL_DX
else if (lCommand == COMM_VIDEOSTATUS) { //COMM_VIDEOSTATUS 0x1600
memcpy(timestamp, ((LPNET_DVR_VIDEOSTATUS)pBuf)->TimeStamp, 20);
fprintf(stderr, "VIDEOSTATUS:FrontID:");
for (i=0; i<32; i++)
fprintf(stderr,"%d ", ((LPNET_DVR_VIDEOSTATUS)pBuf)->byFrontID[i]);
fprintf(stderr, "\n\r");
fprintf(stderr, "VIDEOSTATUS:TimeStamp:%s\n", timestamp);
for (i=0; i<MAX_CHANNUM; i++)
fprintf(stderr, "VIDEOSTATUS:Channel[%d]:status:%s\n", i+1,
((LPNET_DVR_VIDEOSTATUS)pBuf)->status[i] ? "Normal" : "Frame Lose");
}
#endif
#endif
}
//-------------------------------------------------------------------------------------------
else
{
lIndex = *((int32_t *)pBuf);
switch (lCommand)
{
case EXCEPTION_EXCHANGE: // 0x8000 探询设备时网络异常
printf("DVR[%s] network exception\n", sDVRIP);
break;
case EXCEPTION_AUDIOEXCHANGE: // 0x8001 语音对讲异常
printf("lIndex[%d] audioexchange exception\n", lIndex);
break;
case EXCEPTION_ALARM: // 0x8002 报警异常
printf("lIndex[%d] alarm exception\n", lIndex);
break;
case EXCEPTION_PREVIEW: // 0x8003 预览异常
printf("lIndex[%d] preview exception\n", lIndex);
break;
case EXCEPTION_SERIAL: // 0x8004 透明通道异常
printf("lIndex[%d] serial exception\n", lIndex);
break;
default:
break;
}
}
return 1;
}
----------------解决方案--------------------------------------------------------
楼主要先明白,像这样void (*pFunction)(int,int);的变量定义是什么意思.
因为,这一个指向函数的指针变量的申明,这个函数的返回值是void型,函数的参数有二个,都是int型.
例如:
#include<stdio.h>
#include<conio.h>
int RetSum(int,int);
int TestFun(int (*pFunction)(int,int));
int main(void)
{
clrscr();
TestFun(RetSum);
getch();
}
int RetSum(int a,int b)
{
return (a+b);
}
int TestFun(int (*pFunction)(int,int))
{
printf("%d",(*pFunction)(3,4));
}
然后,再看你的那个程序的函数头就不难了吧.
----------------解决方案--------------------------------------------------------