上海交通大学网络教育学院--计算机专业--操作系统作业---操作系统实验报告_进程与进程通信
22)
23)
24)
25)
26)
27)
28)
29)
30) sizeof(char)*msgCnt[nowProcess], strname[nowProcess][SpaceEnum]); if(m_hFileMap == NULL) { QMessageBox::information(NULL,tr("提示"), tr("创建共享内存失败")); return FALSE; } //映射文件映像
31) m_hViewBuf = MapViewOfFile(m_hFileMap, FILE_MAP_ALL_ACCESS, 0, 0, 0);//映
射全部Buffer
32) if(m_hViewBuf == NULL)
33) {
34)
35)
36)
37)
38)
39)
40) QMessageBox::information(NULL,tr("提示"), tr("读取共享内存失败")); return FALSE; } //信号量创建 m_SemaphoreSend = CreateSemaphore(NULL, msgCnt[nowProcess],
msgCnt[nowProcess], strname[nowProcess][SendEnum]);
41) m_SemaphoreReceive = CreateSemaphore(NULL, 0, msgCnt[nowProcess],
strname[nowProcess][ReceiveEnum]);
42)
43)
44)
45)
46)
47)
48)
49)
50)
51)
52)
53)
54)
55) //设置MsgQ头信息 { pMsgInfo = (_MSGQ_HEADER *)m_hViewBuf; pMsgInfo->MsgMaxCount = msgCnt[nowProcess]; pMsgInfo->MsgSize = msgSize[nowProcess]; pMsgInfo->ReadIndex = 0; pMsgInfo->WriteIndex = 0; //从索引0开始写 pMsgInfo->MsgNum = 0; //ReleaseMutex(m_Semaphore); } return TRUE; }
5.4.3、
1)
2)
3)
4)
Send()函数实现 BOOL CMsgQ::Send(LPVOID buf,int whichProcess, DWORD waitTime) { LPCVOID ori; char *lpchar; //地址指针