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.

225 lines
5.7 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 <debug.hxx>
  22. //
  23. // JobFolder related stuff
  24. //
  25. BOOL JFOnProcessAttach(void);
  26. HRESULT JFGetClassObject(REFCLSID cid, REFIID riid, LPVOID *ppvObj);
  27. HRESULT AllocFolderCFs(void);
  28. void FreeFolderCFs(void);
  29. extern HANDLE g_hActCtx;
  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. // init common controls and get activation context
  62. InitCommonControls();
  63. if (!GetCurrentActCtx(&g_hActCtx))
  64. {
  65. ERR_OUT("GetCurrentActCtx", 0);
  66. return FALSE;
  67. }
  68. //
  69. // Disable thread notification from OS
  70. //
  71. DisableThreadLibraryCalls(hInstance);
  72. HRESULT hr;
  73. //
  74. // Init the folder class factory objects.
  75. //
  76. hr = AllocFolderCFs();
  77. if (FAILED(hr))
  78. {
  79. ERR_OUT("AllocFolderCFs", hr);
  80. return FALSE;
  81. }
  82. //
  83. // Initialize the global service values. These are globals that
  84. // live in common\globals.cxx, and are used in both the service
  85. // (mstask.exe) and client (mstask.dll).
  86. //
  87. hr = InitGlobals();
  88. if (FAILED(hr))
  89. {
  90. ERR_OUT("InitGlobals", hr);
  91. FreeFolderCFs();
  92. return FALSE;
  93. }
  94. //
  95. // Init job folder stuff
  96. //
  97. if (JFOnProcessAttach() == FALSE)
  98. {
  99. FreeGlobals();
  100. FreeFolderCFs();
  101. return FALSE;
  102. }
  103. break;
  104. case DLL_PROCESS_DETACH:
  105. schDebugOut((DEB_ITRACE, "DllMain: DLL_PROCESS_DETACH\n"));
  106. #if DBG == 1
  107. CleanUpDebugging();
  108. #endif
  109. FreeGlobals();
  110. FreeFolderCFs();
  111. break;
  112. }
  113. return(TRUE);
  114. }
  115. //+----------------------------------------------------------------------------
  116. //
  117. // Function: DllGetClassObject
  118. //
  119. // Synopsis: Creates a class factory for the requested object.
  120. //
  121. // Arguments: [cid] - the requested class object
  122. // [iid] - the requested interface
  123. // [ppvObj] - returned pointer to class object
  124. //
  125. // Returns: HRESULTS
  126. //
  127. //-----------------------------------------------------------------------------
  128. STDAPI
  129. DllGetClassObject(REFCLSID cid, REFIID iid, void **ppvObj)
  130. {
  131. IUnknown *pUnk = NULL;
  132. HRESULT hr = S_OK;
  133. if (CLSID_CTask == cid)
  134. {
  135. pUnk = CJobCF::Create();
  136. if (pUnk != NULL)
  137. {
  138. hr = pUnk->QueryInterface(iid, ppvObj);
  139. pUnk->Release();
  140. }
  141. else
  142. {
  143. return E_OUTOFMEMORY;
  144. }
  145. }
  146. else if (CLSID_CTaskScheduler == cid)
  147. {
  148. pUnk = CScheduleCF::Create();
  149. if (pUnk != NULL)
  150. {
  151. hr = pUnk->QueryInterface(iid, ppvObj);
  152. pUnk->Release();
  153. }
  154. else
  155. {
  156. return E_OUTOFMEMORY;
  157. }
  158. }
  159. else
  160. {
  161. return JFGetClassObject(cid, iid, ppvObj);
  162. }
  163. return hr;
  164. }
  165. //+----------------------------------------------------------------------------
  166. //
  167. // Function: DllCanUnloadNow
  168. //
  169. // Synopsis: Indicates whether the DLL can be removed if there are no
  170. // objects in existence.
  171. //
  172. // Returns: S_OK or S_FALSE
  173. //
  174. //-----------------------------------------------------------------------------
  175. STDAPI
  176. DllCanUnloadNow(void)
  177. {
  178. return CDll::CanUnloadNow();
  179. }
  180. //+----------------------------------------------------------------------------
  181. //
  182. // Function: AddAtJobWithHash
  183. //
  184. // Synopsis: Client-side stub for this API to make things compile. Only
  185. // supported/called on the server side
  186. //
  187. // Returns: E_NOTIMPL
  188. //
  189. //-----------------------------------------------------------------------------
  190. STDAPI
  191. CSchedule::AddAtJobWithHash(
  192. const AT_INFO &At,
  193. DWORD * pID)
  194. {
  195. return E_NOTIMPL;
  196. }