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.

217 lines
5.2 KiB

  1. //+----------------------------------------------------------------------------
  2. //
  3. // Job Schedule Application Job Object Handler
  4. //
  5. // Microsoft Windows
  6. // Copyright (C) Microsoft Corporation, 1992 - 1996.
  7. //
  8. // File: dllmisc.cxx
  9. //
  10. // Contents: job scheduler class objects handler DLL fcns
  11. //
  12. // History: 25-Sep-95 EricB created
  13. // 23-Feb-01 JBenton added code to clean up debug crit sections
  14. //
  15. //-----------------------------------------------------------------------------
  16. #include "..\pch\headers.hxx"
  17. #pragma hdrstop
  18. DECLARE_INFOLEVEL(Sched);
  19. #include <job_cls.hxx>
  20. #include <sch_cls.hxx>
  21. #include <dynload.hxx>
  22. #include <debug.hxx>
  23. //
  24. // JobFolder related stuff
  25. //
  26. BOOL JFOnProcessAttach(void);
  27. HRESULT JFGetClassObject(REFCLSID cid, REFIID riid, LPVOID *ppvObj);
  28. HRESULT AllocFolderCFs(void);
  29. void FreeFolderCFs(void);
  30. //+----------------------------------------------------------------------------
  31. //
  32. // DLL functions
  33. //
  34. //-----------------------------------------------------------------------------
  35. //+----------------------------------------------------------------------------
  36. //
  37. // Function: DllMain
  38. //
  39. // Synopsis: Provide a DllMain for Win32
  40. //
  41. // Arguments: hInstance - HANDLE to this dll
  42. // dwReason - Reason this function was called. Can be
  43. // Process/Thread Attach/Detach.
  44. //
  45. // Returns: BOOL - TRUE if no error, FALSE otherwise
  46. //
  47. // History: 24-May-95 EricB created.
  48. //
  49. //-----------------------------------------------------------------------------
  50. extern "C" BOOL
  51. DllMain(HINSTANCE hInstance, DWORD dwReason, LPVOID lpReserved)
  52. {
  53. switch (dwReason)
  54. {
  55. case DLL_PROCESS_ATTACH:
  56. schDebugOut((DEB_ITRACE, "DllMain: DLL_PROCESS_ATTACH\n"));
  57. //
  58. // Get instance handle
  59. //
  60. g_hInstance = hInstance;
  61. //
  62. // Disable thread notification from OS
  63. //
  64. DisableThreadLibraryCalls(hInstance);
  65. HRESULT hr;
  66. //
  67. // Init the folder class factory objects.
  68. //
  69. hr = AllocFolderCFs();
  70. if (FAILED(hr))
  71. {
  72. ERR_OUT("AllocFolderCFs", hr);
  73. return FALSE;
  74. }
  75. //
  76. // Initialize the global service values. These are globals that
  77. // live in common\globals.cxx, and are used in both the service
  78. // (mstask.exe) and client (mstask.dll).
  79. //
  80. hr = InitGlobals();
  81. if (FAILED(hr))
  82. {
  83. ERR_OUT("InitGlobals", hr);
  84. return FALSE;
  85. }
  86. //
  87. // Init job folder stuff
  88. //
  89. if (JFOnProcessAttach() == FALSE)
  90. {
  91. return FALSE;
  92. }
  93. break;
  94. case DLL_PROCESS_DETACH:
  95. schDebugOut((DEB_ITRACE, "DllMain: DLL_PROCESS_DETACH\n"));
  96. #if DBG == 1
  97. CleanUpDebugging();
  98. #endif
  99. FreeGlobals();
  100. FreeFolderCFs();
  101. FreeDynLoadLibs();
  102. break;
  103. }
  104. return(TRUE);
  105. }
  106. //+----------------------------------------------------------------------------
  107. //
  108. // Function: DllGetClassObject
  109. //
  110. // Synopsis: Creates a class factory for the requested object.
  111. //
  112. // Arguments: [cid] - the requested class object
  113. // [iid] - the requested interface
  114. // [ppvObj] - returned pointer to class object
  115. //
  116. // Returns: HRESULTS
  117. //
  118. //-----------------------------------------------------------------------------
  119. STDAPI
  120. DllGetClassObject(REFCLSID cid, REFIID iid, void **ppvObj)
  121. {
  122. IUnknown *pUnk = NULL;
  123. HRESULT hr = S_OK;
  124. if (CLSID_CTask == cid)
  125. {
  126. pUnk = CJobCF::Create();
  127. if (pUnk != NULL)
  128. {
  129. hr = pUnk->QueryInterface(iid, ppvObj);
  130. pUnk->Release();
  131. }
  132. else
  133. {
  134. return E_OUTOFMEMORY;
  135. }
  136. }
  137. else if (CLSID_CTaskScheduler == cid)
  138. {
  139. pUnk = CScheduleCF::Create();
  140. if (pUnk != NULL)
  141. {
  142. hr = pUnk->QueryInterface(iid, ppvObj);
  143. pUnk->Release();
  144. }
  145. else
  146. {
  147. return E_OUTOFMEMORY;
  148. }
  149. }
  150. else
  151. {
  152. return JFGetClassObject(cid, iid, ppvObj);
  153. }
  154. return hr;
  155. }
  156. //+----------------------------------------------------------------------------
  157. //
  158. // Function: DllCanUnloadNow
  159. //
  160. // Synopsis: Indicates whether the DLL can be removed if there are no
  161. // objects in existence.
  162. //
  163. // Returns: S_OK or S_FALSE
  164. //
  165. //-----------------------------------------------------------------------------
  166. STDAPI
  167. DllCanUnloadNow(void)
  168. {
  169. return CDll::CanUnloadNow();
  170. }
  171. #if !defined(_CHICAGO_)
  172. //+----------------------------------------------------------------------------
  173. //
  174. // Function: AddAtJobWithHash
  175. //
  176. // Synopsis: Client-side stub for this API to make things compile. Only
  177. // supported/called on the server side
  178. //
  179. // Returns: E_NOTIMPL
  180. //
  181. //-----------------------------------------------------------------------------
  182. STDAPI
  183. CSchedule::AddAtJobWithHash(
  184. const AT_INFO &At,
  185. DWORD * pID)
  186. {
  187. return E_NOTIMPL;
  188. }
  189. #endif // !defined(_CHICAGO_)