?? msgqueue.h
字號(hào):
#if !defined(WEIL_MSGQUEUE_H)
#define WEIL_MSGQUEUE_H
#define MAX_MSG_NUMBER 8192
#define SLEEP_TIME 10
class MsgQueue
{
protected:
struct MSG_QUEUE{
unsigned long DataHead; //消息隊(duì)列頭指針
unsigned long DataTail; //消息隊(duì)列尾指針
unsigned long IndexHead; //數(shù)據(jù)索引頭指針
unsigned long IndexTail; //數(shù)據(jù)索引尾指針
unsigned long Index[MAX_MSG_NUMBER][2]; //數(shù)據(jù)指針數(shù)據(jù)
unsigned long AttachCount; //連接個(gè)數(shù)
unsigned long MQSize; //消息隊(duì)列的大小
}*Data;
char *szBuf; //消息隊(duì)列
HANDLE FileMappingHandle;
HANDLE hSemaForPut; //消息隊(duì)列互斥寫信號(hào)燈
HANDLE hSemaForGet; //消息隊(duì)列互斥讀信號(hào)燈
public:
BOOL ifBlock; //阻塞標(biāo)志,默認(rèn)值為TRUE
BOOL bExitFlag; //退出標(biāo)志
protected:
DWORD P(HANDLE hSema);
BOOL V(HANDLE hSema);
public:
MsgQueue();
~MsgQueue();
int Create(char *MsgQueueName,unsigned long MsgQueueSize); //建立消息隊(duì)列,創(chuàng)建成功返回0,創(chuàng)建不成功也返回-1(同一個(gè)隊(duì)列只能創(chuàng)建一次)
int Open(char *MsgQueueName); //打開消息隊(duì)列,打開成功返回0,不成功則返回-1
int Close(); //關(guān)閉,在使用完消息隊(duì)列后要關(guān)閉(關(guān)閉操作只是解除影射關(guān)系而不是刪除消息隊(duì)列)
int Destory(char *MsgQueueName); //刪除消息隊(duì)列,成功刪除返回0,不成功則返回-1(目前還未實(shí)現(xiàn)Becuase I don't konw how to do that)
int Init(); //置頭尾指針為0(創(chuàng)建消息隊(duì)列時(shí)已經(jīng)把頭尾指針設(shè)置為0)
int GetMsg(char *Buffer); //從消息隊(duì)列中取出一條消息,若返回0則沒有消息,返回-1表示函數(shù)調(diào)用失敗,其他為消息的字節(jié)數(shù);若ifBlock為TRUE,若消息隊(duì)列為空則睡眠等待消息,若ifBlock為FALSE,若消息隊(duì)列為空則立即返回(返回值為0)
int PutMsg(char *Buffer,unsigned long MsgLength); //把一條消息放到消息隊(duì)列中,若返回0則成功,-1為失敗;若ifBlock為TRUE,若消息隊(duì)列滿則睡眠等待直到把該消息放到消息隊(duì)列中才返回,若ifBlock為FALSE,若消息隊(duì)列滿則立即返回(返回值為-1)
int ClsQueue();
}
;
#endif
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -