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.

142 lines
3.8 KiB

  1. // WsbIdb.cpp : Implementation of DLL Exports.
  2. // You will need the NT SUR Beta 2 SDK or VC 4.2 in order to build this
  3. // project. This is because you will need MIDL 3.00.15 or higher and new
  4. // headers and libs. If you have VC 4.2 installed, then everything should
  5. // already be configured correctly.
  6. // Note: Proxy/Stub Information
  7. // To merge the proxy/stub code into the object DLL, add the file
  8. // dlldatax.c to the project. Make sure precompiled headers
  9. // are turned off for this file, and add _MERGE_PROXYSTUB to the
  10. // defines for the project.
  11. //
  12. // Modify the custom build rule for Wsb.idl by adding the following
  13. // files to the Outputs. You can select all of the .IDL files by
  14. // expanding each project and holding Ctrl while clicking on each of them.
  15. // Wsb_p.c
  16. // dlldata.c
  17. // To build a separate proxy/stub DLL,
  18. // run nmake -f Wsbps.mak in the project directory.
  19. #include "stdafx.h"
  20. #include "resource.h"
  21. #include "initguid.h"
  22. #include "wsb.h"
  23. #include "wsbdbsys.h"
  24. #include "wsbdbent.h"
  25. #include "wsbdbkey.h"
  26. //#include "dlldatax.h"
  27. #ifdef _MERGE_PROXYSTUB
  28. extern "C" HINSTANCE hProxyDll;
  29. #endif
  30. CComModule _Module;
  31. BEGIN_OBJECT_MAP(ObjectMap)
  32. OBJECT_ENTRY(CLSID_CWsbDbKey, CWsbDbKey)
  33. OBJECT_ENTRY(CLSID_CWsbDbSys, CWsbDbSys)
  34. END_OBJECT_MAP()
  35. /////////////////////////////////////////////////////////////////////////////
  36. // DLL Entry Point
  37. extern "C"
  38. BOOL WINAPI DllMain(HINSTANCE hInstance, DWORD dwReason, LPVOID lpReserved)
  39. {
  40. lpReserved;
  41. #ifdef _MERGE_PROXYSTUB
  42. if (!PrxDllMain(hInstance, dwReason, lpReserved))
  43. return FALSE;
  44. #endif
  45. if (dwReason == DLL_PROCESS_ATTACH) {
  46. _Module.Init(ObjectMap, hInstance);
  47. DisableThreadLibraryCalls(hInstance);
  48. }
  49. else if (dwReason == DLL_PROCESS_DETACH) {
  50. _Module.Term();
  51. }
  52. return TRUE; // ok
  53. }
  54. /////////////////////////////////////////////////////////////////////////////
  55. // Used to determine whether the DLL can be unloaded by OLE
  56. STDAPI DllCanUnloadNow(void)
  57. {
  58. #ifdef _MERGE_PROXYSTUB
  59. if (PrxDllCanUnloadNow() != S_OK)
  60. return S_FALSE;
  61. #endif
  62. return (_Module.GetLockCount()==0) ? S_OK : S_FALSE;
  63. }
  64. /////////////////////////////////////////////////////////////////////////////
  65. // Returns a class factory to create an object of the requested type
  66. STDAPI DllGetClassObject(REFCLSID rclsid, REFIID riid, LPVOID* ppv)
  67. {
  68. #ifdef _MERGE_PROXYSTUB
  69. if (PrxDllGetClassObject(rclsid, riid, ppv) == S_OK)
  70. return S_OK;
  71. #endif
  72. return _Module.GetClassObject(rclsid, riid, ppv);
  73. }
  74. /////////////////////////////////////////////////////////////////////////////
  75. // DllRegisterServer - Adds entries to the system registry
  76. STDAPI DllRegisterServer(void)
  77. {
  78. #ifdef _MERGE_PROXYSTUB
  79. HRESULT hRes = PrxDllRegisterServer();
  80. if (FAILED(hRes))
  81. return hRes;
  82. // Add service entries
  83. // hRes = _Module.UpdateRegistryFromResourceS(IDR_Wsb, TRUE);
  84. // if (FAILED(hRes))
  85. // return hRes;
  86. #endif
  87. HRESULT hr;
  88. // registers object, typelib and all interfaces in typelib
  89. hr = CoInitialize( 0 );
  90. if (SUCCEEDED(hr)) {
  91. hr = _Module.RegisterServer( FALSE );
  92. CoUninitialize( );
  93. }
  94. return( hr );
  95. }
  96. /////////////////////////////////////////////////////////////////////////////
  97. // DllUnregisterServer - Removes entries from the system registry
  98. STDAPI DllUnregisterServer(void)
  99. {
  100. HRESULT hr;
  101. #ifdef _MERGE_PROXYSTUB
  102. PrxDllUnregisterServer();
  103. #endif
  104. // Remove service entries
  105. // _Module.UpdateRegistryFromResourceS(IDR_Wsb, FALSE);
  106. hr = CoInitialize( 0 );
  107. if (SUCCEEDED(hr)) {
  108. _Module.UnregisterServer();
  109. hr = S_OK;
  110. }
  111. CoUninitialize( );
  112. return( hr );
  113. }