回调函数的实现 & 结构体的继承
------------------------------------------------------------------------------------
[1]
------------------------------------------------------------------------------------
#pragma once //消息类型定义 static const DWORD MESSAGE_TYPE_2PARAM = 1; // 两个填充参数 static const DWORD SVCMSG_CONTENT_LEN = 1024; // 即时消息内容最大长度 static const DWORD SVCMSG_RESULT_LEN = 16; // 即时消息结果最大长度 #pragma pack(8) //回调消息 typedef struct STRUC_BASIC_MESSAGE{ DWORD dwSvcType; DWORD dwMsgType; } BASIC_MESSAGE, *pBASIC_MESSAGE; //回调消息 typedef struct STRUC_BASIC_MESSAGE_EX : public BASIC_MESSAGE{ char chContent[SVCMSG_CONTENT_LEN]; char chResult[SVCMSG_RESULT_LEN]; } BASIC_MESSAGE_EX, *pBASIC_MESSAGE_EX; //消息回调函数原型 typedef DWORD (__stdcall *pMsgBack)(const BASIC_MESSAGE *struMessage); #endif
------------------------------------------------------------------------------------
[2]
------------------------------------------------------------------------------------
pMsgBack m_pMsgFunc; // 服务框架打印消息回调 CMSERVICE_API int WINAPI CMSvc_SetMsgCallback(const pMsgBack msgfunc) { if (NULL == msgfunc) { return -1; } CGlobal::SnglPtr()->m_pMsgFunc = msgfunc; return CMSvc_NO_ERROR; }
------------------------------------------------------------------------------------
[3]
------------------------------------------------------------------------------------
void CGlobal::PrintMsgUtf8(const std::string & sMsg) { if (NULL == m_pMsgFunc) { return; } BASIC_MESSAGE_EX msgEx; //需要根据具体的服务器类型修改下面的参数 msgEx.dwSvcType = cms_8100::MT_SERVICE_CMS;//数据服务器 msgEx.dwMsgType = MESSAGE_TYPE_2PARAM; wstring wsTime = GetCurTimeWStr(); string sMsgWithTime = myutils::UTF8_W2A(wsTime) + sMsg; strcpy_s(msgEx.chContent, sMsgWithTime.c_str()); strcpy_s(msgEx.chResult, ""); m_pMsgFunc(&msgEx); }
------------------------------------------------------------------------------------
posted on 2014-04-08 10:20 xuejianhui 阅读(448) 评论(0) 编辑 收藏 举报