发送端
// mail2.cpp : 定义控制台应用程序的入口点。
//
#include "stdafx.h"
#include "windows.h"
#include "stdio.h"
int _tmain(int argc, _TCHAR* argv[])
{
char szMailAddr[]="\\\\.\\mailslot\\mymails";
int i=0;
char buffer[1024];
HANDLE Myhandle;
Myhandle = CreateFile(
L"\\\\.\\mailslot\\mymails",
GENERIC_WRITE,
FILE_SHARE_READ,
NULL,
OPEN_EXISTING,
FILE_ATTRIBUTE_NORMAL,
NULL
);
DWORD DY=0;
memset(buffer,0,1023);
while(1)
{
sprintf(buffer,"Send Message = %d!!!",i);
WriteFile(Myhandle,buffer,1022,&DY,NULL);
printf("%d\n",i);
i++;
//Sleep(1000);
}
return 0;
}
//接收端
// mail1.cpp : 定义控制台应用程序的入口点。
//
#include "stdafx.h"
#include "windows.h"
#include "stdio.h"
int _tmain(int argc, _TCHAR* argv[])
{
char szMailAddr[]="\\\\.\\mailslot\\mymails";
char buffer[1024];
HANDLE Myhandle;
Myhandle = CreateMailslot(
L"\\\\.\\mailslot\\mymails",
0,
MAILSLOT_WAIT_FOREVER,
NULL
);
DWORD DY=0;
memset(buffer,0,1023);
while(1)
{
while(ReadFile(Myhandle,buffer,1022,&DY,NULL))
{
//Sleep(100);
printf("%s\n",buffer);
}
}
return 0;
}