Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

93 lines
2.0 KiB

  1. /*++
  2. Copyright (c) 1990 Microsoft Corporation
  3. Module Name:
  4. tmslot.c
  5. Abstract:
  6. Test program to Win32 mailslot API calls
  7. Author:
  8. Manny Weiser (mannyw) 5-Mar-1991
  9. Revision History:
  10. --*/
  11. #include "stdio.h"
  12. #include "windows.h"
  13. #define BUFFER_SIZE 100
  14. char Buffer[BUFFER_SIZE];
  15. DWORD
  16. main(
  17. int argc,
  18. char *argv[],
  19. char *envp[]
  20. )
  21. {
  22. BOOL success;
  23. HANDLE handle;
  24. LPSTR mailslotName = "\\\\.\\mailslot\\asdf";
  25. DWORD maxMessageSize, nextSize, messageCount, readTimeout;
  26. DWORD bytesRead;
  27. handle = CreateMailslot( mailslotName,
  28. 100,
  29. MAILSLOT_WAIT_FOREVER,
  30. NULL );
  31. if (handle == (HANDLE)-1) {
  32. printf ("Failed to open mailslot ""%s""\n", mailslotName);
  33. return 1;
  34. }
  35. printf ("Successfully opened the mailslot.\n");
  36. success = SetMailslotInfo( handle,
  37. atoi( argv[1] ) );
  38. if (!success) {
  39. printf ("Failed to set information for mailslot\n");
  40. return 1;
  41. }
  42. printf ("Set mailslot timeout to %d\n", atoi(argv[1]) );
  43. success = GetMailslotInfo( handle,
  44. &maxMessageSize,
  45. &nextSize,
  46. &messageCount,
  47. &readTimeout );
  48. if (!success) {
  49. printf ("Failed to get information for mailslot\n");
  50. return 1;
  51. }
  52. printf ("Max message size = %d\n", maxMessageSize );
  53. printf ("Next message size = %d\n", nextSize );
  54. printf ("Message count = %d\n", messageCount );
  55. printf ("Read timeout = %u\n", readTimeout );
  56. success = ReadFile( handle,
  57. Buffer,
  58. BUFFER_SIZE,
  59. &bytesRead,
  60. NULL );
  61. if (!success) {
  62. printf ("Failed to read mailslot\n");
  63. return 1;
  64. } else {
  65. printf ("Successfully read %d bytes '%s'\n", bytesRead, Buffer );
  66. }
  67. }