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.

166 lines
4.3 KiB

  1. /*++
  2. Module Name:
  3. hsmeng.cpp
  4. Abstract:
  5. DLL main for Engine
  6. Author:
  7. Ran Kalach [rankala] 28-July-1999
  8. Revision History:
  9. --*/
  10. // hsmeng.cpp : Implementation of DLL Exports.
  11. // Note: Currently, Engine proxy/stub is compiled into a different DLL.
  12. // Below is relevant information if it is decided to merge the two DLLs.
  13. // Note: Proxy/Stub Information
  14. // To merge the proxy/stub code into the object DLL, add the file
  15. // dlldatax.c to the project. Make sure precompiled headers
  16. // are turned off for this file, and add _MERGE_PROXYSTUB to the
  17. // defines for the project.
  18. //
  19. // If you are not running WinNT4.0 or Win95 with DCOM, then you
  20. // need to remove the following define from dlldatax.c
  21. // #define _WIN32_WINNT 0x0400
  22. //
  23. // Further, if you are running MIDL without /Oicf switch, you also
  24. // need to remove the following define from dlldatax.c.
  25. // #define USE_STUBLESS_PROXY
  26. //
  27. // Modify the custom build rule for ...int.idl by adding the following
  28. // files to the Outputs.
  29. // ...
  30. // dlldata.c
  31. // To build a separate proxy/stub DLL,
  32. // run nmake -f ...ps.mk in the project directory.
  33. #include "stdafx.h"
  34. #include "initguid.h"
  35. #include "HsmServ.h"
  36. #include "HsmMgdRs.h"
  37. #include "HsmMgdRc.h"
  38. #include "HsmStgPl.h"
  39. #include "mountmed.h"
  40. #include "task.h"
  41. #include "metalib.h"
  42. #include <stdio.h>
  43. #ifdef _MERGE_PROXYSTUB
  44. extern "C" HINSTANCE hProxyDll;
  45. #endif
  46. #define WSB_TRACE_IS WSB_TRACE_BIT_HSMENG
  47. CComModule _Module;
  48. BEGIN_OBJECT_MAP(ObjectMap)
  49. OBJECT_ENTRY(CLSID_HsmServer, CHsmServer)
  50. OBJECT_ENTRY(CLSID_CHsmUpgradeRmsDb, CHsmUpgradeRmsDb)
  51. OBJECT_ENTRY(CLSID_CHsmManagedResource, CHsmManagedResource)
  52. OBJECT_ENTRY(CLSID_CHsmManagedResourceCollection, CHsmManagedResourceCollection)
  53. OBJECT_ENTRY(CLSID_CHsmStoragePool, CHsmStoragePool)
  54. OBJECT_ENTRY(CLSID_CMountingMedia, CMountingMedia)
  55. END_OBJECT_MAP()
  56. /////////////////////////////////////////////////////////////////////////////
  57. // DLL Entry Point
  58. extern "C"
  59. BOOL WINAPI DllMain(HINSTANCE hInstance, DWORD dwReason, LPVOID lpReserved)
  60. {
  61. lpReserved;
  62. #ifdef _MERGE_PROXYSTUB
  63. if (!PrxDllMain(hInstance, dwReason, lpReserved))
  64. return FALSE;
  65. #endif
  66. if (dwReason == DLL_PROCESS_ATTACH)
  67. {
  68. _Module.Init(ObjectMap, hInstance);
  69. DisableThreadLibraryCalls(hInstance);
  70. }
  71. else if (dwReason == DLL_PROCESS_DETACH)
  72. _Module.Term();
  73. return TRUE; // ok
  74. }
  75. /////////////////////////////////////////////////////////////////////////////
  76. // Used to determine whether the DLL can be unloaded by OLE
  77. STDAPI DllCanUnloadNow(void)
  78. {
  79. #ifdef _MERGE_PROXYSTUB
  80. if (PrxDllCanUnloadNow() != S_OK)
  81. return S_FALSE;
  82. #endif
  83. return (_Module.GetLockCount()==0) ? S_OK : S_FALSE;
  84. }
  85. /////////////////////////////////////////////////////////////////////////////
  86. // Returns a class factory to create an object of the requested type
  87. STDAPI DllGetClassObject(REFCLSID rclsid, REFIID riid, LPVOID* ppv)
  88. {
  89. #ifdef _MERGE_PROXYSTUB
  90. if (PrxDllGetClassObject(rclsid, riid, ppv) == S_OK)
  91. return S_OK;
  92. #endif
  93. return _Module.GetClassObject(rclsid, riid, ppv);
  94. }
  95. /////////////////////////////////////////////////////////////////////////////
  96. // DllRegisterServer - Adds entries to the system registry
  97. STDAPI DllRegisterServer(void)
  98. {
  99. HRESULT hr;
  100. #ifdef _MERGE_PROXYSTUB
  101. HRESULT hRes = PrxDllRegisterServer();
  102. if (FAILED(hRes))
  103. return hRes;
  104. #endif
  105. // registers object, typelib and all interfaces in typelib
  106. hr = CoInitialize( 0 );
  107. if (SUCCEEDED(hr)) {
  108. hr = _Module.RegisterServer( FALSE );
  109. CoUninitialize( );
  110. }
  111. return( hr );
  112. }
  113. /////////////////////////////////////////////////////////////////////////////
  114. // DllUnregisterServer - Removes entries from the system registry
  115. STDAPI DllUnregisterServer(void)
  116. {
  117. HRESULT hr;
  118. #ifdef _MERGE_PROXYSTUB
  119. PrxDllUnregisterServer();
  120. #endif
  121. hr = CoInitialize( 0 );
  122. if (SUCCEEDED(hr)) {
  123. _Module.UnregisterServer();
  124. CoUninitialize( );
  125. hr = S_OK;
  126. }
  127. return( hr );
  128. }