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.

164 lines
4.4 KiB

  1. // Wsb.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 "wsbcltn.h"
  24. #include "wsbenum.h"
  25. #include "wsbguid.h"
  26. #include "wsbstrg.h"
  27. #include "wsbtrc.h"
  28. #include "dlldatax.h"
  29. #ifdef _MERGE_PROXYSTUB
  30. extern "C" HINSTANCE hProxyDll;
  31. #endif
  32. CComModule _Module;
  33. BEGIN_OBJECT_MAP(ObjectMap)
  34. OBJECT_ENTRY(CLSID_CWsbGuid, CWsbGuid)
  35. OBJECT_ENTRY(CLSID_CWsbIndexedEnum, CWsbIndexedEnum)
  36. OBJECT_ENTRY(CLSID_CWsbOrderedCollection, CWsbOrderedCollection)
  37. OBJECT_ENTRY(CLSID_CWsbString, CWsbString)
  38. OBJECT_ENTRY(CLSID_CWsbTrace, CWsbTrace)
  39. END_OBJECT_MAP()
  40. /////////////////////////////////////////////////////////////////////////////
  41. // DLL Entry Point
  42. extern "C"
  43. BOOL WINAPI DllMain(HINSTANCE hInstance, DWORD dwReason, LPVOID lpReserved)
  44. {
  45. lpReserved;
  46. #ifdef _MERGE_PROXYSTUB
  47. if (!PrxDllMain(hInstance, dwReason, lpReserved))
  48. return FALSE;
  49. #endif
  50. switch (dwReason) {
  51. case DLL_PROCESS_ATTACH:
  52. _Module.Init(ObjectMap, hInstance);
  53. WsbTraceInit();
  54. break;
  55. case DLL_THREAD_DETACH :
  56. WsbTraceCleanupThread();
  57. break;
  58. case DLL_PROCESS_DETACH:
  59. WsbTraceCleanupThread();
  60. WsbTraceTerminate();
  61. _Module.Term();
  62. break;
  63. default:
  64. break;
  65. }
  66. return TRUE; // ok
  67. }
  68. /////////////////////////////////////////////////////////////////////////////
  69. // Used to determine whether the DLL can be unloaded by OLE
  70. STDAPI DllCanUnloadNow(void)
  71. {
  72. #ifdef _MERGE_PROXYSTUB
  73. if (PrxDllCanUnloadNow() != S_OK)
  74. return S_FALSE;
  75. #endif
  76. return (_Module.GetLockCount()==0) ? S_OK : S_FALSE;
  77. }
  78. /////////////////////////////////////////////////////////////////////////////
  79. // Returns a class factory to create an object of the requested type
  80. STDAPI DllGetClassObject(REFCLSID rclsid, REFIID riid, LPVOID* ppv)
  81. {
  82. #ifdef _MERGE_PROXYSTUB
  83. if (PrxDllGetClassObject(rclsid, riid, ppv) == S_OK)
  84. return S_OK;
  85. #endif
  86. return _Module.GetClassObject(rclsid, riid, ppv);
  87. }
  88. /////////////////////////////////////////////////////////////////////////////
  89. // DllRegisterServer - Adds entries to the system registry
  90. STDAPI DllRegisterServer(void)
  91. {
  92. HRESULT hr = S_OK;
  93. #ifdef _MERGE_PROXYSTUB
  94. hr = PrxDllRegisterServer();
  95. if( FAILED( hr ) )
  96. return hr;
  97. #endif
  98. #if 0
  99. // Add service entries
  100. hr = _Module.UpdateRegistryFromResourceS(IDR_Wsb, TRUE);
  101. if( FAILED( hr ) )
  102. return hr;
  103. #endif
  104. hr = WsbRegisterEventLogSource( WSB_LOG_APP, WSB_LOG_SOURCE_NAME,
  105. WSB_LOG_SVC_CATCOUNT, WSB_LOG_SVC_CATFILE, WSB_LOG_SVC_MSGFILES );
  106. if( FAILED( hr ) ) return( hr );
  107. // registers object, typelib and all interfaces in typelib
  108. CoInitialize( 0 );
  109. hr = _Module.RegisterServer( FALSE );
  110. CoUninitialize( );
  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. #if 0
  122. // Remove service entries
  123. _Module.UpdateRegistryFromResourceS(IDR_Wsb, FALSE);
  124. #endif
  125. WsbUnregisterEventLogSource( WSB_LOG_APP, WSB_LOG_SOURCE_NAME );
  126. hr = CoInitialize( 0 );
  127. if (SUCCEEDED(hr)) {
  128. _Module.UnregisterServer();
  129. CoUninitialize( );
  130. hr = S_OK;
  131. }
  132. return( hr );
  133. }