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.

118 lines
3.0 KiB

  1. // This sample demonstrates how to use the IFaxControl COM interface.
  2. #include <conio.h>
  3. #include <iostream>
  4. // Import the fax service fxsocm.dll file so that fax service COM object can be used.
  5. // The typical path to fxsocm.dll is shown.
  6. // If this path is not correct, search for fxsocm.dll and replace with the right path.
  7. // The path below will be used during compile-time only. At run-time, the path is never used.
  8. #import "c:\Windows\System32\setup\fxsocm.dll" no_namespace
  9. using namespace std;
  10. int main (int argc, char *argv[])
  11. {
  12. try
  13. {
  14. HRESULT hr;
  15. //
  16. // Define variables.
  17. //
  18. IFaxControlPtr sipFaxControl;
  19. //
  20. // Initialize the COM library on the current thread.
  21. //
  22. hr = CoInitialize(NULL);
  23. if (FAILED(hr))
  24. {
  25. _com_issue_error(hr);
  26. }
  27. //
  28. // Create the object.
  29. //
  30. hr = sipFaxControl.CreateInstance("FaxControl.FaxControl.1");
  31. if (FAILED(hr))
  32. {
  33. _com_issue_error(hr);
  34. }
  35. //
  36. // Test for the existance of the Fax component
  37. //
  38. if (!sipFaxControl->IsFaxServiceInstalled)
  39. {
  40. //
  41. // Fax isn't installed
  42. //
  43. printf ("Fax is NOT installed.\n");
  44. if (2 == argc && !stricmp ("install", argv[1]))
  45. {
  46. //
  47. // Use asked us to install fax
  48. //
  49. printf ("Installing fax...\n");
  50. sipFaxControl->InstallFaxService();
  51. return 0;
  52. }
  53. else
  54. {
  55. printf ("Run this tool again with 'install' command line argument to install fax.\n");
  56. return 0;
  57. }
  58. }
  59. else
  60. {
  61. //
  62. // Fax is installed
  63. //
  64. printf ("Fax is installed.\n");
  65. }
  66. //
  67. // Test for the existance of a local Fax Printer
  68. //
  69. if (!sipFaxControl->IsLocalFaxPrinterInstalled)
  70. {
  71. //
  72. // Fax printer isn't installed
  73. //
  74. printf ("Fax printer is NOT installed.\n");
  75. if (2 == argc && !stricmp ("install", argv[1]))
  76. {
  77. //
  78. // Use asked us to install fax
  79. //
  80. printf ("Installing fax printer...\n");
  81. sipFaxControl->InstallLocalFaxPrinter();
  82. return 0;
  83. }
  84. else
  85. {
  86. printf ("Run this tool again with 'install' command line argument to install a fax printer.\n");
  87. return 0;
  88. }
  89. }
  90. else
  91. {
  92. //
  93. // Fax printer is installed
  94. //
  95. printf ("Fax printer is installed.\n");
  96. }
  97. }
  98. catch (_com_error& e)
  99. {
  100. cout <<
  101. "Error. HRESULT message is: \"" <<
  102. e.ErrorMessage() <<
  103. "\" (" <<
  104. e.Error() <<
  105. ")" <<
  106. endl;
  107. if (e.ErrorInfo())
  108. {
  109. cout << (char *)e.Description() << endl;
  110. }
  111. }
  112. CoUninitialize();
  113. return 0;
  114. }