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.

186 lines
4.6 KiB

  1. #include <windows.h>
  2. #include <stdio.h>
  3. #include "faxutil.h"
  4. #include "winfax.h"
  5. typedef struct _EVENT_STRINGS {
  6. DWORD EventId;
  7. LPWSTR EventStr;
  8. } EVENT_STRINGS, *PEVENT_STRINGS;
  9. EVENT_STRINGS EventStrings[] =
  10. {
  11. FEI_DIALING, L"Dialing",
  12. FEI_SENDING, L"Sending",
  13. FEI_RECEIVING, L"Receiving",
  14. FEI_COMPLETED, L"Completed",
  15. FEI_BUSY, L"Busy",
  16. FEI_NO_ANSWER, L"No Answer",
  17. FEI_BAD_ADDRESS, L"Bad Address",
  18. FEI_NO_DIAL_TONE, L"No Dial Tone",
  19. FEI_DISCONNECTED, L"Disconnected",
  20. FEI_FATAL_ERROR, L"Fatal Error",
  21. FEI_NOT_FAX_CALL, L"Not a Fax Call",
  22. FEI_CALL_DELAYED, L"Call Delayed",
  23. FEI_CALL_BLACKLISTED, L"Call Blacklisted",
  24. FEI_RINGING, L"Ringing",
  25. FEI_ABORTING, L"Aborting",
  26. FEI_ROUTING, L"Routing",
  27. FEI_MODEM_POWERED_ON, L"Modem Powered Off",
  28. FEI_MODEM_POWERED_OFF, L"Modem Powered On",
  29. FEI_IDLE, L"Idle",
  30. FEI_FAXSVC_ENDED, L"Fax Service Ended",
  31. 0, L"Unknown Event"
  32. };
  33. #define NumEventStrings ((sizeof(EventStrings)/sizeof(EVENT_STRINGS))-1)
  34. HANDLE CompletionPort;
  35. BOOL
  36. ConsoleHandlerRoutine(
  37. DWORD CtrlType
  38. )
  39. {
  40. if (CtrlType == CTRL_C_EVENT) {
  41. PostQueuedCompletionStatus( CompletionPort, 0, (DWORD) -1, 0 );
  42. return TRUE;
  43. }
  44. return FALSE;
  45. }
  46. PFAX_PORT_INFO_1
  47. MyFaxEnumPorts(
  48. HFAX hFaxSvc,
  49. LPDWORD pcPorts
  50. )
  51. {
  52. PVOID pSvcPorts = NULL;
  53. DWORD cb;
  54. if (!FaxEnumPorts(hFaxSvc, (LPBYTE*) &pSvcPorts, &cb, 1, pcPorts))
  55. {
  56. pSvcPorts = NULL;
  57. }
  58. return pSvcPorts;
  59. }
  60. int _cdecl
  61. wmain(
  62. int argc,
  63. wchar_t *argv[]
  64. )
  65. {
  66. HFAX hFax = NULL;
  67. PFAX_EVENT FaxEvent;
  68. BOOL Rval;
  69. DWORD Bytes;
  70. DWORD CompletionKey;
  71. SYSTEMTIME EvtTime;
  72. PFAX_PORT_INFO_1 PortInfo;
  73. DWORD PortCount;
  74. DWORD i;
  75. FAX_PORT_HANDLE FaxPortHandle = 0;
  76. LPWSTR ComputerName = NULL;
  77. HeapInitialize(NULL,NULL,NULL,0);
  78. if (argc > 1) {
  79. ComputerName = argv[1];
  80. }
  81. if( !FaxConnectFaxServer( ComputerName, &hFax ) ){
  82. wprintf( L"FaxConnectFaxServer failed ec = %d\n", GetLastError() );
  83. return -1;
  84. }
  85. CompletionPort = CreateIoCompletionPort(
  86. INVALID_HANDLE_VALUE,
  87. NULL,
  88. 0,
  89. 1
  90. );
  91. if (!CompletionPort) {
  92. wprintf( L"CreateIoCompletionPort() failed, ec=0x%08x\n", GetLastError() );
  93. return -1;
  94. }
  95. PortInfo = MyFaxEnumPorts( hFax, &PortCount );
  96. if (!PortInfo) {
  97. wprintf( L"MyFaxEnumPorts() failed, ec=0x%08x\n", GetLastError() );
  98. return -1;
  99. }
  100. for (i=0; i<PortCount; i++) {
  101. Rval = FaxOpenPort( hFax, PortInfo[i].DeviceId, PORT_OPEN_EVENTS, &FaxPortHandle );
  102. if (!Rval) {
  103. wprintf( L"FaxOpenPort() failed, ec=0x%08x\n", GetLastError() );
  104. }
  105. }
  106. if (!FaxInitializeEventQueue( hFax, CompletionPort, 0 )) {
  107. wprintf( L"FaxInitializeEvent() failed, ec=0x%08x\n", GetLastError() );
  108. return -1;
  109. }
  110. SetConsoleCtrlHandler( ConsoleHandlerRoutine, TRUE );
  111. while (TRUE) {
  112. Rval = GetQueuedCompletionStatus(
  113. CompletionPort,
  114. &Bytes,
  115. &CompletionKey,
  116. (LPOVERLAPPED*) &FaxEvent,
  117. INFINITE
  118. );
  119. if (!Rval) {
  120. wprintf( L"GetQueuedCompletionStatus() failed, ec=0x%08x\n", GetLastError() );
  121. return -1;
  122. }
  123. if (CompletionKey == (DWORD)-1) {
  124. wprintf( L"\n\n-----------------------------------------\n" );
  125. wprintf( L"Control-C pressed\n" );
  126. wprintf( L"StatTest Ending\n" );
  127. wprintf( L"-----------------------------------------\n" );
  128. break;
  129. }
  130. FileTimeToSystemTime( &FaxEvent->TimeStamp, &EvtTime );
  131. for (i=0; i<NumEventStrings; i++) {
  132. if (FaxEvent->EventId == EventStrings[i].EventId) {
  133. break;
  134. }
  135. }
  136. wprintf( L"%02d:%02d:%02d.%03d hServer=0x%08x, hPort=0x%08x, device=0x%08x, event=0x%08x %ws\n",
  137. EvtTime.wHour,
  138. EvtTime.wMinute,
  139. EvtTime.wSecond,
  140. EvtTime.wMilliseconds,
  141. FaxEvent->FaxServerHandle,
  142. FaxEvent->FaxPortHandle,
  143. FaxEvent->DeviceId,
  144. FaxEvent->EventId,
  145. EventStrings[i].EventStr
  146. );
  147. LocalFree( FaxEvent );
  148. }
  149. if (hFax) {
  150. Rval = FaxDisconnectFaxServer( hFax );
  151. }
  152. return -1;
  153. }