vc之線程和進(jìn)程之用命名管道實(shí)現(xiàn)進(jìn)程間通信

vc之線程和進(jìn)程之用命名管道實(shí)現(xiàn)進(jìn)程間通信

ID:34419009

大?。?50.50 KB

頁(yè)數(shù):8頁(yè)

時(shí)間:2019-03-06

vc之線程和進(jìn)程之用命名管道實(shí)現(xiàn)進(jìn)程間通信_(tái)第1頁(yè)
vc之線程和進(jìn)程之用命名管道實(shí)現(xiàn)進(jìn)程間通信_(tái)第2頁(yè)
vc之線程和進(jìn)程之用命名管道實(shí)現(xiàn)進(jìn)程間通信_(tái)第3頁(yè)
vc之線程和進(jìn)程之用命名管道實(shí)現(xiàn)進(jìn)程間通信_(tái)第4頁(yè)
vc之線程和進(jìn)程之用命名管道實(shí)現(xiàn)進(jìn)程間通信_(tái)第5頁(yè)
資源描述:

《vc之線程和進(jìn)程之用命名管道實(shí)現(xiàn)進(jìn)程間通信》由會(huì)員上傳分享,免費(fèi)在線閱讀,更多相關(guān)內(nèi)容在工程資料-天天文庫(kù)。

1、一、創(chuàng)建應(yīng)用工程???????1、創(chuàng)建單文檔應(yīng)用工程????????2、添加新單文檔應(yīng)用工程二、編輯菜單項(xiàng)???????1、編輯Thread工程之菜單項(xiàng)???????2、編輯Child工程之菜單項(xiàng)三、添加變量、函數(shù)???????1、添加變量?????????????a、為CThreadView類添加變量?????????????b、為CChildView類添加變量???????2、添加函數(shù)?????????????a、為CThreadView類添加菜單消息響應(yīng)函數(shù)?????????????b、為CChildView類添

2、加菜單消息響應(yīng)函數(shù)四、添加代碼???????1、為CThreadView類添加代碼?????????????a、添加初始化代碼CThreadView::CThreadView(){?//TODO:addconstructioncodehere???pipe=NULL;}CThreadView::~CThreadView(){?if(pipe)?CloseHandle(pipe);}?????????????b、添加消息響應(yīng)函數(shù)代碼voidCThreadView::OnPipeCreate(){?//TODO:Addyo

3、urcommandhandlercodehere?pipe=CreateNamedPipe("\\.\pipe\mypipe",PIPE_ACCESS_DUPLEX

4、FILE_FLAG_OVERLAPPED,0,1,1024,1024,0,NULL);?if(INVALID_HANDLE_VALUE==pipe)?{??MessageBox("管道創(chuàng)建失敗");??pipe=NULL;??return;?}?HANDLEevent;?event=CreateEvent(NULL,TRUE,FALSE,NULL)

5、;?if(!event)?{??MessageBox("事件對(duì)象創(chuàng)建失敗");??CloseHandle(pipe);??pipe=NULL;??return;?}?OVERLAPPEDoverlap;?ZeroMemory(&overlap,sizeof(OVERLAPPED));?overlap.hEvent=event;?ConnectNamedPipe(pipe,&overlap);???????????????????????????????????//等待客戶端連接???WaitForSingleObjec

6、t(event,INFINITE);?}voidCThreadView::OnPipeRead(){?//TODO:Addyourcommandhandlercodehere??charreadbuf[100];?DWORDdwread;?ReadFile(pipe,readbuf,100,&dwread,NULL);??MessageBox(readbuf);?}voidCThreadView::OnPipeWrite(){?//TODO:Addyourcommandhandlercodehere??charbuf[

7、]="你好,長(zhǎng)江!";?DWORDdwwrite;?WriteFile(pipe,buf,strlen(buf)+1,&dwwrite,NULL);?}???????2、為CChildView類添加代碼?????????????a、添加初始化代碼CChildView::CChildView(){?//TODO:addconstructioncodehere???pipe=NULL;}CChildView::~CChildView(){?if(pipe)??CloseHandle(pipe);}?????????????

8、b、添加消息響應(yīng)函數(shù)代碼voidCChildView::OnConnect(){?//TODO:Addyourcommandhandlercodehere?WaitNamedPipe("\\.\pipe\mypipe",NMPWAIT_WAIT_FOREVER);?pipe=CreateFile"\\.\pipe\mypipe",GENERIC_READ

9、GENERIC_WRITE,0,NULL,OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL,NULL);?}voidCChild

10、View::OnRead(){?//TODO:Addyourcommandhandlercodehere??charreadbuf[100];?DWORDdwread;?ReadFile(pipe,readbuf,100,&dwread,NULL);??MessageBox(readbuf);?}voidCChildView::O

當(dāng)前文檔最多預(yù)覽五頁(yè),下載文檔查看全文

此文檔下載收益歸作者所有

當(dāng)前文檔最多預(yù)覽五頁(yè),下載文檔查看全文
溫馨提示:
1. 部分包含數(shù)學(xué)公式或PPT動(dòng)畫(huà)的文件,查看預(yù)覽時(shí)可能會(huì)顯示錯(cuò)亂或異常,文件下載后無(wú)此問(wèn)題,請(qǐng)放心下載。
2. 本文檔由用戶上傳,版權(quán)歸屬用戶,天天文庫(kù)負(fù)責(zé)整理代發(fā)布。如果您對(duì)本文檔版權(quán)有爭(zhēng)議請(qǐng)及時(shí)聯(lián)系客服。
3. 下載前請(qǐng)仔細(xì)閱讀文檔內(nèi)容,確認(rèn)文檔內(nèi)容符合您的需求后進(jìn)行下載,若出現(xiàn)內(nèi)容與標(biāo)題不符可向本站投訴處理。
4. 下載文檔時(shí)可能由于網(wǎng)絡(luò)波動(dòng)等原因無(wú)法下載或下載錯(cuò)誤,付費(fèi)完成后未能成功下載的用戶請(qǐng)聯(lián)系客服處理。