// console.cpp : 定義控制台應用程式的入口點。
//
#include "stdafx.h"
#include <iostream>
using namespace std;
typedef unsigned char UCHAR;
int FunA();
int FunB();
int FunC();
typedef enum tagMsgType
{
MSG_TYPE_A = 1,
MSG_TYPE_B,
MSG_TYPE_C
};
typedef int (*MSG_PROC_FUNC)();
typedef struct tagMsgDispatchTbl
{
UCHAR ucMsgType;
MSG_PROC_FUNC pFuc;
} MsgDispatchTbl;
MsgDispatchTbl g_astDispatchTbl[] =
{
{MSG_TYPE_A, FunA},
{MSG_TYPE_B, FunB},
{MSG_TYPE_C, FunC},
};
int FunA()
{
printf("Call FunA\r\n");
return 0;
}
int FunB()
{
printf("Call FunB\r\n");
return 0;
}
int FunC()
{
printf("Call FunC\r\n");
return 0;
}
int _tmain(int argc, _TCHAR* argv[])
{
int i = 1;
int iRet = 0;
UCHAR ucMsgType = MSG_TYPE_B;
UCHAR aucStr[1024] = {0};
MSG_PROC_FUNC pFunc;
for (i = 1; i < 4; i++)
{
if (ucMsgType == g_astDispatchTbl[i].ucMsgType)
{
pFunc = g_astDispatchTbl[i].pFuc;
pFunc();
}
}
return 0;
}