Just a test. Master ignores.
Service side:
Code by pnig0s1992//date:2012,3,19 #include <stdio.h> #include <Windows.h> VOID usemailslot (
LPTSTR lpmailslotname);
int main (int argc,char **argv) {LPTSTR lpslotname = TEXT ("\\\\.\\mailslot\\first_slot");
Usemailslot (Lpslotname);
return 0;
} VOID Usemailslot (LPTSTR lpmailslotname) {HANDLE hmailslot;
BOOL Bresult;
DWORD dwmessagesize;
DWORD Dwmessagecount;
DWORD dwhasreadbytes;
Hmailslot = Createmailslot (lpmailslotname,0,mailslot_wait_forever,null);
if (Hmailslot = = Invalid_handle_value) {printf ("\ncreate mailslot:%s failed.", Lpmailslotname);
Return
}else {printf ("\ncreate mailslot successfully.");
int icount = 0;
int index = 0;
while (1) {bresult = Getmailslotinfo (hmailslot,null,&dwmessagesize,&dwmessagecount,null); if (!bresult) {printf ("\ngeTmailslotinfo failed with error:%d ", GetLastError ());
CloseHandle (Hmailslot);
Return
} if (Dwmessagecount = = 0) {printf ("\nno.%d wait for message.", icount+1);
icount++;
Sleep (2000);
Continue
while (dwmessagecount!= 0) {LPTSTR Lpmessagebuffer = (LPTSTR) HeapAlloc (getprocessheap
(), heap_zero_memory,dwmessagesize);
if (Lpmessagebuffer = = NULL) {printf ("\nheapalloc failed with error:%d", GetLastError ());
CloseHandle (Hmailslot);
Return
} bresult = ReadFile (hmailslot,lpmessagebuffer,dwmessagesize,&dwhasreadbytes,null);
if (!bresult) {printf ("\nreadfile failed with error:%d", GetLastError ());
HeapFree (GetProcessHeap (), 0,lpmessagebuffer); ClOsehandle (Hmailslot);
Return
printf ("\nreceive no.%d message from client.\ncontent:%s", Index+1,lpmessagebuffer);
index++;
HeapFree (GetProcessHeap (), 0,lpmessagebuffer);
Bresult = Getmailslotinfo (hmailslot,0,&dwmessagesize,&dwmessagecount,null);
if (!bresult) {printf ("\ngetmailslotinfo failed with error:%d", GetLastError ());
Return
}} return; }