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.

273 lines
6.8 KiB

  1. /*++
  2. Copyright (c) 1998 Microsoft Corporation
  3. Module Name:
  4. simple.c
  5. Abstract:
  6. This module implements a simple command line fax-send utility
  7. --*/
  8. #include <windows.h>
  9. #include <winbase.h>
  10. #include <stdio.h>
  11. #include <stdlib.h>
  12. #include <winfax.h>
  13. #include <tchar.h>
  14. #include <assert.h>
  15. #include <shellapi.h>
  16. #ifdef DBG
  17. char szDebugBuffer[80];
  18. #define DEBUG(parm1,parm2)\
  19. {\
  20. wsprintf(szDebugBuffer, parm1, parm2);\
  21. OutputDebugString(szDebugBuffer);\
  22. }
  23. #else
  24. #define DEBUG(parm1,parm2)
  25. #endif
  26. void GiveUsage(
  27. LPTSTR AppName
  28. )
  29. {
  30. _tprintf( TEXT("Usage : %s /d <full path to doc> /n <number>\n --send a fax\n"),AppName);
  31. _tprintf( TEXT("Usage : %s /? -- this message\n"),AppName);
  32. }
  33. void PrintDeviceStatus(
  34. PFAX_DEVICE_STATUS fds
  35. )
  36. {
  37. TCHAR SubmitBuffer[100];
  38. TCHAR StartBuffer[100];
  39. SYSTEMTIME SystemTime;
  40. if (!fds) {
  41. return;
  42. }
  43. _tprintf(TEXT("Device Id:\t\t%d\n"),fds->DeviceId );
  44. _tprintf(TEXT("Device Name:\t\t%s\n"),fds->DeviceName );
  45. _tprintf(TEXT("CallerId:\t\t%s\n"),fds->CallerId );
  46. _tprintf(TEXT("CSID:\t\t\t%s\n"),fds->Csid );
  47. _tprintf(TEXT("TSID:\t\t\t%s\n"),fds->Tsid );
  48. _tprintf(TEXT("Page:\t\t\t%d of %d\n"),fds->CurrentPage,fds->TotalPages );
  49. _tprintf(TEXT("DocumentName:\t\t%s\n"),fds->DocumentName);
  50. _tprintf(TEXT("JobType:\t\t%d\n"),fds->JobType);
  51. _tprintf(TEXT("PhoneNumber:\t\t%s\n"),fds->PhoneNumber);
  52. _tprintf(TEXT("SenderName:\t\t%s\n"),fds->SenderName);
  53. _tprintf(TEXT("RecipientName:\t\t%s\n"),fds->RecipientName);
  54. _tprintf(TEXT("Size (in bytes):\t%d\n"),fds->Size);
  55. _tprintf(TEXT("Status (see FPS flags):\t%x\n"),fds->Status);
  56. FileTimeToSystemTime(&fds->StartTime,&SystemTime);
  57. GetTimeFormat(LOCALE_SYSTEM_DEFAULT,
  58. LOCALE_NOUSEROVERRIDE,
  59. &SystemTime,
  60. NULL,
  61. StartBuffer,
  62. sizeof(StartBuffer)
  63. );
  64. FileTimeToSystemTime(&fds->SubmittedTime,&SystemTime);
  65. SystemTimeToTzSpecificLocalTime(NULL,&SystemTime,&SystemTime);
  66. GetTimeFormat(LOCALE_SYSTEM_DEFAULT,
  67. LOCALE_NOUSEROVERRIDE,
  68. &SystemTime,
  69. NULL,
  70. SubmitBuffer,
  71. sizeof(SubmitBuffer)
  72. );
  73. _tprintf(TEXT("Job Submited at %s\n"),SubmitBuffer);
  74. _tprintf(TEXT("Job transmission started at %s\n\n"),StartBuffer);
  75. }
  76. int _cdecl
  77. main(
  78. int argc,
  79. char *argvA[]
  80. )
  81. /*++
  82. Routine Description:
  83. Entry point to the setup program
  84. Arguments:
  85. argc - Number of args.
  86. argvA - the commandline arguments.
  87. Return Value:
  88. --*/
  89. {
  90. LPTSTR *argv;
  91. int argcount = 0;
  92. TCHAR Document[MAX_PATH] = {0};
  93. TCHAR Number[64] = {0};
  94. HANDLE hFax;
  95. HANDLE hCompletionPort = INVALID_HANDLE_VALUE;
  96. PFAX_JOB_PARAM JobParam;
  97. PFAX_COVERPAGE_INFO CoverpageInfo;
  98. DWORD JobId;
  99. DWORD dwBytes, CompletionKey;
  100. PFAX_EVENT FaxEvent;
  101. BOOL bTerminate = FALSE;
  102. HANDLE hPort;
  103. PFAX_DEVICE_STATUS DeviceStatus;
  104. //
  105. // do commandline stuff
  106. //
  107. #ifdef UNICODE
  108. argv = CommandLineToArgvW( GetCommandLine(), &argc );
  109. #else
  110. argv = argvA;
  111. #endif
  112. DEBUG ("Number of arguments = %d\n",argc);
  113. for (argcount=0;argcount<argc;argcount++) {
  114. DEBUG ("Arg %d:",argcount);
  115. DEBUG (" %s\n",argv[argcount]);
  116. }
  117. // check for commandline switches
  118. for (argcount=0; argcount<argc; argcount++) {
  119. if ((argv[argcount][0] == L'/') || (argv[argcount][0] == L'-')) {
  120. switch (towlower(argv[argcount][1])) {
  121. case 'n':
  122. lstrcpy(Number, argv[argcount+1]);
  123. break;
  124. case 'd':
  125. lstrcpy(Document, argv[argcount+1]);
  126. break;
  127. case '?':
  128. GiveUsage(argv[0]);
  129. return 0;
  130. default:
  131. break;
  132. }
  133. }
  134. }
  135. if (!Number[0] || !Document[0]) {
  136. _tprintf( TEXT("Missing args.\n") );
  137. GiveUsage(argv[0]);
  138. return -1;
  139. }
  140. //
  141. // connect to fax service
  142. //
  143. if (!FaxConnectFaxServer(NULL,&hFax)) {
  144. _tprintf( TEXT("FaxConnectFaxServer failed, ec = %d\n"),GetLastError() );
  145. return -1;
  146. }
  147. assert (hFax != NULL);
  148. hCompletionPort = CreateIoCompletionPort(INVALID_HANDLE_VALUE,NULL,0,0);
  149. if (!hCompletionPort) {
  150. _tprintf( TEXT("CreateIoCompletionPort failed, ec = %d\n"), GetLastError() );
  151. FaxClose( hFax );
  152. return -1;
  153. }
  154. if (!FaxInitializeEventQueue(hFax,
  155. hCompletionPort,
  156. 0,
  157. NULL,
  158. 0 ) ) {
  159. _tprintf( TEXT("FaxInitializeEventQueue failed, ec = %d\n"), GetLastError() );
  160. FaxClose( hFax );
  161. return -1;
  162. }
  163. FaxCompleteJobParams(&JobParam,&CoverpageInfo);
  164. JobParam->RecipientNumber = Number;
  165. if (!FaxSendDocument( hFax, Document, JobParam, NULL , &JobId) ) {
  166. _tprintf( TEXT("FaxSendDocument failed, ec = %d \n"), GetLastError() );
  167. FaxClose( hFax );
  168. CloseHandle( hCompletionPort );
  169. FaxFreeBuffer(JobParam);
  170. FaxFreeBuffer(CoverpageInfo);
  171. return -1;
  172. }
  173. _tprintf( TEXT("Queued document %s for transmition to %s, JobID = %d\n"),
  174. Document,
  175. Number,
  176. JobId );
  177. FaxFreeBuffer( JobParam );
  178. FaxFreeBuffer( CoverpageInfo );
  179. while (!bTerminate && GetQueuedCompletionStatus(hCompletionPort,
  180. &dwBytes,
  181. &CompletionKey,
  182. (LPOVERLAPPED *)&FaxEvent,
  183. INFINITE) ) {
  184. _tprintf( TEXT("Received event %x\n"),FaxEvent->EventId);
  185. switch (FaxEvent->EventId) {
  186. case FEI_IDLE:
  187. case FEI_COMPLETED:
  188. case FEI_MODEM_POWERED_ON:
  189. case FEI_MODEM_POWERED_OFF:
  190. case FEI_FAXSVC_ENDED:
  191. bTerminate = TRUE;
  192. break;
  193. case FEI_JOB_QUEUED:
  194. _tprintf( TEXT("JobId %d queued\n"),FaxEvent->JobId );
  195. break;
  196. case FEI_DIALING:
  197. case FEI_SENDING:
  198. case FEI_RECEIVING:
  199. case FEI_BUSY:
  200. case FEI_NO_ANSWER:
  201. case FEI_BAD_ADDRESS:
  202. case FEI_NO_DIAL_TONE:
  203. case FEI_DISCONNECTED:
  204. case FEI_FATAL_ERROR:
  205. if (FaxOpenPort( hFax, FaxEvent->DeviceId,PORT_OPEN_QUERY, &hPort) ) {
  206. if (FaxGetDeviceStatus(hPort,&DeviceStatus) ) {
  207. PrintDeviceStatus(DeviceStatus);
  208. FaxFreeBuffer( DeviceStatus );
  209. }
  210. FaxClose( hPort );
  211. }
  212. break;
  213. }
  214. }
  215. FaxClose( hFax );
  216. CloseHandle( hCompletionPort );
  217. return 1;
  218. }