1 #include <stdio.h> 2 #include <stdlib.h> 3 #include <string.h> 4 #include <windows.h> 5 #include <tchar.h> 6 7 #define BUFSIZE 1024 8 #define MAILSLOT_TIMEOUT 1000 9 10 11 int main(int argc, char *argv[]) 12 { 13 HANDLE hMailslot; 14 LPSTR lpszMailslotName = "\\\\.\\MAILSLOT\\mymailslot"; 15 LPSTR lpszTestMessage = "Mailslot test message!"; 16 DWORD cbLength, cbWritten; 17 18 hMailslot = CreateFile(lpszMailslotName, 19 GENERIC_WRITE, 20 FILE_SHARE_READ, 21 (LPSECURITY_ATTRIBUTES)NULL, 22 OPEN_EXISTING, 23 FILE_ATTRIBUTE_NORMAL, 24 (HANDLE)NULL); 25 printf("hMailslot %x\n", (DWORD)hMailslot); 26 if (hMailslot == INVALID_HANDLE_VALUE) 27 { 28 printf("CreateFile() failed\n"); 29 return 0; 30 } 31 32 cbLength = (ULONG)strlen(lpszTestMessage)+1; 33 34 WriteFile(hMailslot, 35 lpszTestMessage, 36 cbLength, 37 &cbWritten, 38 NULL); 39 40 CloseHandle(hMailslot); 41 42 return 0; 43 } 44 45 /* EOF */ 46 47