프로세스 간 통신: 우체통
6681 단어 통신
// MailslotSvrView.cpp : implementation of the CMailslotSvrView class
//
#include "stdafx.h"
#include "MailslotSvr.h"
#include "MailslotSvrDoc.h"
#include "MailslotSvrView.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CMailslotSvrView
IMPLEMENT_DYNCREATE(CMailslotSvrView, CView)
BEGIN_MESSAGE_MAP(CMailslotSvrView, CView)
//{{AFX_MSG_MAP(CMailslotSvrView)
ON_COMMAND(IDM_MAILSLOT_RECV, OnMailslotRecv)
//}}AFX_MSG_MAP
// Standard printing commands
ON_COMMAND(ID_FILE_PRINT, CView::OnFilePrint)
ON_COMMAND(ID_FILE_PRINT_DIRECT, CView::OnFilePrint)
ON_COMMAND(ID_FILE_PRINT_PREVIEW, CView::OnFilePrintPreview)
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CMailslotSvrView construction/destruction
CMailslotSvrView::CMailslotSvrView()
{
// TODO: add construction code here
}
CMailslotSvrView::~CMailslotSvrView()
{
}
BOOL CMailslotSvrView::PreCreateWindow(CREATESTRUCT& cs)
{
// TODO: Modify the Window class or styles here by modifying
// the CREATESTRUCT cs
return CView::PreCreateWindow(cs);
}
/////////////////////////////////////////////////////////////////////////////
// CMailslotSvrView drawing
void CMailslotSvrView::OnDraw(CDC* pDC)
{
CMailslotSvrDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
// TODO: add draw code for native data here
}
/////////////////////////////////////////////////////////////////////////////
// CMailslotSvrView printing
BOOL CMailslotSvrView::OnPreparePrinting(CPrintInfo* pInfo)
{
// default preparation
return DoPreparePrinting(pInfo);
}
void CMailslotSvrView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add extra initialization before printing
}
void CMailslotSvrView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add cleanup after printing
}
/////////////////////////////////////////////////////////////////////////////
// CMailslotSvrView diagnostics
#ifdef _DEBUG
void CMailslotSvrView::AssertValid() const
{
CView::AssertValid();
}
void CMailslotSvrView::Dump(CDumpContext& dc) const
{
CView::Dump(dc);
}
CMailslotSvrDoc* CMailslotSvrView::GetDocument() // non-debug version is inline
{
ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CMailslotSvrDoc)));
return (CMailslotSvrDoc*)m_pDocument;
}
#endif //_DEBUG
/////////////////////////////////////////////////////////////////////////////
// CMailslotSvrView message handlers
void CMailslotSvrView::OnMailslotRecv()
{
// TODO: Add your command handler code here
HANDLE hMailslot;
hMailslot = CreateMailslot("\\\\.\\mailslot\\MyMailslot",0,
MAILSLOT_WAIT_FOREVER,NULL);
if(INVALID_HANDLE_VALUE == hMailslot)
{
MessageBox(" ");
return;
}
char buf[100];
DWORD dwRead;
if(!ReadFile(hMailslot,buf,100,&dwRead,NULL))
{
MessageBox(" ");
CloseHandle(hMailslot);
return;
}
MessageBox(buf);
CloseHandle(hMailslot);
}
// MailslotClientView.cpp : implementation of the CMailslotClientView class
//
#include "stdafx.h"
#include "MailslotClient.h"
#include "MailslotClientDoc.h"
#include "MailslotClientView.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CMailslotClientView
IMPLEMENT_DYNCREATE(CMailslotClientView, CView)
BEGIN_MESSAGE_MAP(CMailslotClientView, CView)
//{{AFX_MSG_MAP(CMailslotClientView)
ON_COMMAND(IDM_MAILSLOT_SEND, OnMailslotSend)
//}}AFX_MSG_MAP
// Standard printing commands
ON_COMMAND(ID_FILE_PRINT, CView::OnFilePrint)
ON_COMMAND(ID_FILE_PRINT_DIRECT, CView::OnFilePrint)
ON_COMMAND(ID_FILE_PRINT_PREVIEW, CView::OnFilePrintPreview)
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CMailslotClientView construction/destruction
CMailslotClientView::CMailslotClientView()
{
// TODO: add construction code here
}
CMailslotClientView::~CMailslotClientView()
{
}
BOOL CMailslotClientView::PreCreateWindow(CREATESTRUCT& cs)
{
// TODO: Modify the Window class or styles here by modifying
// the CREATESTRUCT cs
return CView::PreCreateWindow(cs);
}
/////////////////////////////////////////////////////////////////////////////
// CMailslotClientView drawing
void CMailslotClientView::OnDraw(CDC* pDC)
{
CMailslotClientDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
// TODO: add draw code for native data here
}
/////////////////////////////////////////////////////////////////////////////
// CMailslotClientView printing
BOOL CMailslotClientView::OnPreparePrinting(CPrintInfo* pInfo)
{
// default preparation
return DoPreparePrinting(pInfo);
}
void CMailslotClientView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add extra initialization before printing
}
void CMailslotClientView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add cleanup after printing
}
/////////////////////////////////////////////////////////////////////////////
// CMailslotClientView diagnostics
#ifdef _DEBUG
void CMailslotClientView::AssertValid() const
{
CView::AssertValid();
}
void CMailslotClientView::Dump(CDumpContext& dc) const
{
CView::Dump(dc);
}
CMailslotClientDoc* CMailslotClientView::GetDocument() // non-debug version is inline
{
ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CMailslotClientDoc)));
return (CMailslotClientDoc*)m_pDocument;
}
#endif //_DEBUG
/////////////////////////////////////////////////////////////////////////////
// CMailslotClientView message handlers
void CMailslotClientView::OnMailslotSend()
{
HANDLE hMailslot;
hMailslot = CreateFile("\\\\.\\mailslot\\MyMailslot",GENERIC_WRITE,
FILE_SHARE_READ,NULL,OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL,NULL);
if(INVALID_HANDLE_VALUE == hMailslot)
{
MessageBox(" ");
return;
}
char buf[]="http://www.cn";
DWORD dwWrite;
if(!WriteFile(hMailslot,buf,strlen(buf)+1,&dwWrite,NULL))
{
MessageBox(" ");
CloseHandle(hMailslot);
return;
}
CloseHandle(hMailslot);
}
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
CAN 통신용 IC에 도전(일단 하드측까지 2017-12-18)이 기사는 의 18 일째 기사입니다. takamasavvv입니다. 갑작스럽지만, 일신상의 사정으로 CAN 통신을 시작하게 되었습니다. 아직 완전히 구현되지 않았기 때문에 이번에는 하드웨어만 했어요 일기를 씁니다. C...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.