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.

188 lines
4.0 KiB

  1. //+---------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1994 - 1996.
  5. //
  6. // File: main.cxx
  7. //
  8. // Contents: Entry point
  9. //
  10. // History: 03-31-95 DavidMun Created
  11. //
  12. //----------------------------------------------------------------------------
  13. #include <headers.hxx>
  14. #pragma hdrstop
  15. #include "jt.hxx"
  16. //
  17. // Forward references
  18. //
  19. HRESULT Init();
  20. VOID Cleanup();
  21. //+---------------------------------------------------------------------------
  22. //
  23. // Function: main
  24. //
  25. // Synopsis: Entry point for DRT.
  26. //
  27. // Arguments: See DisplayUsage().
  28. //
  29. // Returns: 1 on success, 0 on failure
  30. //
  31. // History: 03-31-95 DavidMun Created
  32. //
  33. //----------------------------------------------------------------------------
  34. ULONG __cdecl main(int argc, char *argv[])
  35. {
  36. HRESULT hr = S_OK;
  37. WCHAR *pwszCommandLine;
  38. if (argc == 1)
  39. {
  40. DisplayUsage();
  41. g_Log.SuppressHeaderFooter(TRUE);
  42. return 1;
  43. }
  44. do
  45. {
  46. hr = Init();
  47. BREAK_ON_FAILURE(hr);
  48. pwszCommandLine = GetCommandLineW();
  49. // Point past the zero'th arg
  50. while (iswspace(*pwszCommandLine))
  51. {
  52. pwszCommandLine++;
  53. }
  54. pwszCommandLine += lstrlenA(argv[0]);
  55. // leading spaces and quotes were stripped off in argv[0]
  56. // this will compensate, most of the time
  57. while (!iswspace(*pwszCommandLine))
  58. {
  59. pwszCommandLine++;
  60. }
  61. hr = ProcessCommandLine(pwszCommandLine);
  62. } while (0);
  63. Cleanup();
  64. return FAILED(hr) ? 1 : 0;
  65. }
  66. //+---------------------------------------------------------------------------
  67. //
  68. // Function: Init
  69. //
  70. // Synopsis: Initialize OLE and globals.
  71. //
  72. // Returns: S_OK - initialization successful
  73. // E_* - error logged
  74. //
  75. // Modifies: [g_Log], [g_*Factory], [g_prepmgr]
  76. //
  77. // History: 04-24-95 DavidMun Created
  78. //
  79. //----------------------------------------------------------------------------
  80. HRESULT Init()
  81. {
  82. HRESULT hr = S_OK;
  83. do
  84. {
  85. g_Log.SuppressHeaderFooter(TRUE);
  86. g_Log.SetInfoLevel(g_Log.GetInfoLevel() & ~LOG_DEBUG);
  87. hr = CoInitialize(NULL);
  88. if( FAILED(hr))
  89. {
  90. g_Log.Write(LOG_FAIL, "CoInitialize hr=%#010x", hr);
  91. break;
  92. }
  93. hr = CoCreateInstance(
  94. CLSID_CTask,
  95. NULL,
  96. CLSCTX_INPROC_SERVER,
  97. IID_ITask,
  98. (void **)&g_pJob);
  99. LOG_AND_BREAK_ON_FAIL(hr, "CoCreateInstance(CLSID_CTask)");
  100. #if 0 // BUGBUG queue objects not yet available
  101. hr = CoCreateInstance(
  102. CLSID_CTaskQueue,
  103. NULL,
  104. CLSCTX_INPROC_SERVER,
  105. IID_ITaskQueue,
  106. (void **)&g_pJobQueue);
  107. LOG_AND_BREAK_ON_FAIL(hr, "CoCreateInstance(CLSID_CTaskQueue)");
  108. #endif
  109. hr = CoCreateInstance(
  110. CLSID_CTaskScheduler,
  111. NULL,
  112. CLSCTX_INPROC_SERVER,
  113. IID_ITaskScheduler,
  114. (void **)&g_pJobScheduler);
  115. LOG_AND_BREAK_ON_FAIL(hr, "CoCreateInstance(CLSID_CTaskScheduler)");
  116. }
  117. while (0);
  118. return hr;
  119. }
  120. //+---------------------------------------------------------------------------
  121. //
  122. // Function: Cleanup
  123. //
  124. // Synopsis: Do shutdown processing.
  125. //
  126. // History: 01-02-96 DavidMun Created
  127. // 01-30-96 DavidMun Release enumerators
  128. //
  129. //----------------------------------------------------------------------------
  130. VOID Cleanup()
  131. {
  132. ULONG i;
  133. if (g_pJob)
  134. {
  135. SaveIfDirty(g_pJob);
  136. g_pJob->Release();
  137. g_pJob = NULL;
  138. }
  139. if (g_pJobQueue)
  140. {
  141. SaveIfDirty(g_pJobQueue);
  142. g_pJobQueue->Release();
  143. g_pJobQueue = NULL;
  144. }
  145. for (i = 0; i < NUM_ENUMERATOR_SLOTS; i++)
  146. {
  147. if (g_apEnumJobs[i])
  148. {
  149. g_apEnumJobs[i]->Release();
  150. }
  151. }
  152. CoUninitialize();
  153. }