Advertisement
Guest User

Untitled

a guest
Dec 20th, 2014
176
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.20 KB | None | 0 0
  1. #define UNICODE
  2. #define WIN32_WINNT 0x0500
  3. #include <stdio.h>
  4. #include <windows.h>
  5. #include <signal.h>
  6.  
  7.  
  8.  
  9. HANDLE hPipe;
  10. DWORD WINAPI ServerProc(LPVOID lpVoid)
  11. {
  12.  
  13.  
  14. hPipe = CreateNamedPipe(L"\\.\pipe\testpipe", PIPE_ACCESS_DUPLEX, PIPE_TYPE_BYTE | PIPE_READMODE_BYTE |PIPE_WAIT, 1, 256, 256, 0, NULL);
  15. if(!hPipe)
  16. return wprintf(L"ERROR : Cannot create pipe.n");
  17.  
  18. while(ConnectNamedPipe(hPipe, NULL))
  19. {
  20. WCHAR szText[80] = {0};
  21. DWORD dwSize;
  22. INT i;
  23.  
  24. ReadFile(hPipe, szText, 158, &dwSize, NULL);
  25.  
  26. for(i = 0; i < dwSize; i++)
  27. szText[i] ^= '#';
  28.  
  29. WriteFile(hPipe, szText, 158, &dwSize, NULL);
  30. FlushFileBuffers(hPipe);
  31. DisconnectNamedPipe(hPipe);
  32. }
  33.  
  34. CloseHandle(hPipe);
  35.  
  36. return 0;
  37. }
  38.  
  39. void SignalHandler(int signal)
  40. {
  41. DisconnectNamedPipe(hPipe);
  42. CloseHandle(hPipe);
  43. printf("Application closing...n");
  44. exit(0);
  45. }
  46.  
  47.  
  48. int wmain(void)
  49. {
  50. HANDLE hThread;
  51.  
  52. signal(SIGINT, SignalHandler);
  53.  
  54. hThread = CreateThread(NULL, 0, ServerProc, NULL, 0, NULL);
  55.  
  56. WaitForSingleObject(hThread, INFINITE);
  57.  
  58. CloseHandle(hThread);
  59. }
  60.  
  61. if (signal(signum, SIG_IGN) != SIG_IGN)
  62. signal(signum, sighandler);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement