Leaked source code of windows server 2003
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.

104 lines
2.6 KiB

  1. #include <windows.h>
  2. #include <winioctl.h>
  3. #include <stdio.h>
  4. #include <malloc.h>
  5. #include <emsapi.h>
  6. int _cdecl wmain(int argc, WCHAR **argv)
  7. {
  8. EMSRawChannel* channel;
  9. UCHAR Buffer[256];
  10. ULONG CharCount;
  11. UCHAR AssembledString[1024];
  12. ULONG TotalCharCount;
  13. SAC_CHANNEL_OPEN_ATTRIBUTES Attributes;
  14. DWORD dwStatus;
  15. HANDLE LockEvent;
  16. LockEvent = CreateEvent( NULL, FALSE, FALSE, NULL );
  17. if (LockEvent == INVALID_HANDLE_VALUE) {
  18. return 0;
  19. }
  20. //
  21. // Configure the new channel
  22. //
  23. Attributes.Type = ChannelTypeVTUTF8;
  24. Attributes.Name = L"locker";
  25. Attributes.Description = NULL;
  26. Attributes.Flags = SAC_CHANNEL_FLAG_LOCK_EVENT;
  27. Attributes.CloseEvent = NULL;
  28. Attributes.HasNewDataEvent = NULL;
  29. Attributes.LockEvent = LockEvent;
  30. Attributes.ApplicationType = NULL;
  31. //
  32. // Open the Hello channel
  33. //
  34. channel = EMSRawChannel::Construct(Attributes);
  35. //
  36. // See if the channel was created
  37. //
  38. if (channel == NULL) {
  39. return 0;
  40. }
  41. do {
  42. //
  43. // Write to the Hello Channel
  44. //
  45. if (channel->Write(
  46. (PBYTE)"Hello, World! waiting for lock event!\r\n",
  47. sizeof("Hello, World! waiting for lock event!\r\n")
  48. )) {
  49. printf("Successfully printed string to channel\n");
  50. } else {
  51. printf("Failed to print string to channel\n");
  52. break;
  53. }
  54. dwStatus = WaitForSingleObject(
  55. LockEvent,
  56. INFINITE
  57. );
  58. switch (dwStatus) {
  59. case WAIT_OBJECT_0:
  60. if (channel->Write(
  61. (PBYTE)"Received lock event!\r\n",
  62. sizeof("Received lock event!\r\n")
  63. )) {
  64. printf("Successfully printed string to channel\n");
  65. } else {
  66. printf("Failed to print string to channel\n");
  67. break;
  68. }
  69. break;
  70. default:
  71. if (channel->Write(
  72. (PBYTE)"DID NOT RECEIVE lock event!\r\n",
  73. sizeof("DID NOT RECEIVE lock event!\r\n")
  74. )) {
  75. printf("Successfully printed string to channel\n");
  76. } else {
  77. printf("Failed to print string to channel\n");
  78. break;
  79. }
  80. break;
  81. }
  82. } while (FALSE);
  83. //
  84. // Close the Hello Channel
  85. //
  86. delete channel;
  87. return 0;
  88. }