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.

245 lines
5.8 KiB

  1. ///////////////////////////////////////////////////////////////////////////////
  2. //
  3. // Copyright (c) 2000, Microsoft Corp. All rights reserved.
  4. //
  5. // FILE
  6. //
  7. // iasjet.cpp
  8. //
  9. // SYNOPSIS
  10. //
  11. // Implementation of DLL exports for an ATL in proc server.
  12. //
  13. // MODIFICATION HISTORY
  14. //
  15. // 04/13/2000 Original version.
  16. //
  17. ///////////////////////////////////////////////////////////////////////////////
  18. #include <windows.h>
  19. #include <atlbase.h>
  20. CComModule _Module;
  21. #include <atlcom.h>
  22. #include <resource.h>
  23. #include <attrdnary.h>
  24. #include <iasdb.h>
  25. #include <oledbstore.h>
  26. #include <netshhelper.h>
  27. #include <setup.h>
  28. BEGIN_OBJECT_MAP(ObjectMap)
  29. OBJECT_ENTRY(__uuidof(AttributeDictionary), AttributeDictionary)
  30. OBJECT_ENTRY(__uuidof(OleDBDataStore), OleDBDataStore)
  31. OBJECT_ENTRY(__uuidof(CIASNetshJetHelper), CIASNetshJetHelper)
  32. END_OBJECT_MAP()
  33. //////////
  34. // DLL Entry Point
  35. //////////
  36. BOOL
  37. WINAPI
  38. DllMain(
  39. HINSTANCE hInstance,
  40. DWORD dwReason,
  41. LPVOID lpReserved
  42. )
  43. {
  44. if (dwReason == DLL_PROCESS_ATTACH)
  45. {
  46. _Module.Init(ObjectMap, hInstance);
  47. DisableThreadLibraryCalls(hInstance);
  48. }
  49. else if (dwReason == DLL_PROCESS_DETACH)
  50. {
  51. _Module.Term();
  52. }
  53. return TRUE;
  54. }
  55. //////////
  56. // Used to determine whether the DLL can be unloaded by OLE
  57. //////////
  58. STDAPI DllCanUnloadNow()
  59. {
  60. return (_Module.GetLockCount()==0) ? S_OK : S_FALSE;
  61. }
  62. //////////
  63. // Returns a class factory to create an object of the requested type.
  64. //////////
  65. STDAPI DllGetClassObject(REFCLSID rclsid, REFIID riid, LPVOID* ppv)
  66. {
  67. return _Module.GetClassObject(rclsid, riid, ppv);
  68. }
  69. //////////
  70. // DllRegisterServer - Adds entries to the system registry
  71. //////////
  72. STDAPI DllRegisterServer()
  73. {
  74. HRESULT hr = _Module.UpdateRegistryFromResource(
  75. IDR_REGISTRY,
  76. TRUE,
  77. NULL
  78. );
  79. ////////////////////////////////////////////////////////////////////
  80. // Do the upgrade even if the registration failed. the upgrade code
  81. // does not rely on the registration.
  82. ////////////////////////////////////////////////////////////////////
  83. CIASUpgrade Upgrade;
  84. // ignore return value, FALSE = not called from Netshell
  85. Upgrade.IASUpgrade(FALSE);
  86. return hr;
  87. }
  88. //////////
  89. // DllUnregisterServer - Removes entries from the system registry
  90. //////////
  91. STDAPI DllUnregisterServer()
  92. {
  93. _Module.UpdateRegistryFromResource(
  94. IDR_REGISTRY,
  95. FALSE,
  96. NULL
  97. );
  98. return S_OK;
  99. }
  100. // Flag indicating whether we are running in-proc.
  101. BOOL theInprocFlag = TRUE;
  102. BOOL
  103. WINAPI
  104. IASIsInprocServer()
  105. {
  106. return theInprocFlag;
  107. }
  108. // The AppID for IAS Jet Database Access.
  109. struct __declspec(uuid("{A5CEB593-CCC3-486B-AB91-9C5C5ED4C9E1}")) theAppID;
  110. // Event used to signal the service to stop.
  111. HANDLE theStopEvent;
  112. // Service control handler.
  113. VOID
  114. WINAPI
  115. ServiceHandler(
  116. DWORD fdwControl // requested control code
  117. )
  118. {
  119. switch (fdwControl)
  120. {
  121. case SERVICE_CONTROL_SHUTDOWN:
  122. case SERVICE_CONTROL_STOP:
  123. SetEvent(theStopEvent);
  124. }
  125. }
  126. // Service Main.
  127. VOID
  128. WINAPI
  129. ServiceMain(
  130. DWORD /* dwArgc */,
  131. LPWSTR* /* lpszArgv */
  132. )
  133. {
  134. // We're being used as a service.
  135. theInprocFlag = FALSE;
  136. SERVICE_STATUS status =
  137. {
  138. SERVICE_WIN32_OWN_PROCESS, // dwServiceType;
  139. SERVICE_START_PENDING, // dwCurrentState;
  140. SERVICE_ACCEPT_STOP |
  141. SERVICE_ACCEPT_SHUTDOWN, // dwControlsAccepted;
  142. NO_ERROR, // dwWin32ExitCode;
  143. 0, // dwServiceSpecificExitCode;
  144. 0, // dwCheckPoint;
  145. 0 // dwWaitHint;
  146. };
  147. // Register the service control handler.
  148. SERVICE_STATUS_HANDLE statusHandle = RegisterServiceCtrlHandlerW(
  149. L"IASJet",
  150. ServiceHandler
  151. );
  152. // Let the SCM know we're starting.
  153. SetServiceStatus(statusHandle, &status);
  154. // Create the stop event.
  155. theStopEvent = CreateEvent(NULL, TRUE, FALSE, NULL);
  156. if (theStopEvent)
  157. {
  158. // Initialize the COM run-time.
  159. HRESULT hr = CoInitializeEx(NULL, COINIT_MULTITHREADED);
  160. if (SUCCEEDED(hr))
  161. {
  162. // Get the security settings from our AppID key in the registry.
  163. hr = CoInitializeSecurity(
  164. (PVOID)&__uuidof(theAppID),
  165. -1,
  166. NULL,
  167. NULL,
  168. 0,
  169. 0,
  170. NULL,
  171. EOAC_APPID,
  172. NULL
  173. );
  174. if (SUCCEEDED(hr))
  175. {
  176. // Register the class objects we support.
  177. hr = _Module.RegisterClassObjects(
  178. CLSCTX_LOCAL_SERVER,
  179. REGCLS_MULTIPLEUSE
  180. );
  181. if (SUCCEEDED(hr))
  182. {
  183. // Let the SCM know we're running.
  184. status.dwCurrentState = SERVICE_RUNNING;
  185. SetServiceStatus(statusHandle, &status);
  186. // Wait until someone tells us to stop.
  187. WaitForSingleObject(theStopEvent, INFINITE);
  188. status.dwCurrentState = SERVICE_STOP_PENDING;
  189. SetServiceStatus(statusHandle, &status);
  190. // Revoke the class objects.
  191. _Module.RevokeClassObjects();
  192. }
  193. }
  194. // Shutdown the COM runtime.
  195. CoUninitialize();
  196. }
  197. // Clean-up the stop event.
  198. CloseHandle(theStopEvent);
  199. theStopEvent = NULL;
  200. status.dwWin32ExitCode = hr;
  201. }
  202. else
  203. {
  204. status.dwWin32ExitCode = GetLastError();
  205. }
  206. // We're stopped.
  207. status.dwCurrentState = SERVICE_STOPPED;
  208. SetServiceStatus(statusHandle, &status);
  209. }
  210. #include <newop.cpp>
  211. #include <atlimpl.cpp>