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.

127 lines
3.0 KiB

  1. // ContRot.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 build a separate proxy/stub DLL,
  8. // run nmake -f ContRotps.mak in the project directory.
  9. #include "stdafx.h"
  10. #include <new>
  11. #include "resource.h"
  12. #include "initguid.h"
  13. #include "ContRot.h"
  14. #include "RotObj.h"
  15. #include "debug.h"
  16. #include "Monitor.h"
  17. #include "lock.h"
  18. #define IID_DEFINED
  19. #include "ContRot_i.c"
  20. CMonitor* g_pMonitor = NULL;
  21. extern HINSTANCE g_hModuleInstance;
  22. CContRotModule _Module;
  23. BEGIN_OBJECT_MAP(ObjectMap)
  24. OBJECT_ENTRY(CLSID_ContentRotator, CContentRotator)
  25. END_OBJECT_MAP()
  26. LONG
  27. CContRotModule::Lock()
  28. {
  29. _ASSERT( g_pMonitor != NULL );
  30. return CComModule::Lock();
  31. }
  32. LONG
  33. CContRotModule::Unlock()
  34. {
  35. LONG lc;
  36. CLock l(m_cs);
  37. if ( ( lc = CComModule::Unlock() ) == 0 )
  38. {
  39. // final unlock
  40. _ASSERT( g_pMonitor != NULL );
  41. g_pMonitor->StopAllMonitoring();
  42. }
  43. return lc;
  44. }
  45. /////////////////////////////////////////////////////////////////////////////
  46. // DLL Entry Point
  47. extern "C"
  48. BOOL WINAPI DllMain(HINSTANCE hInstance, DWORD dwReason, LPVOID /*lpReserved*/)
  49. {
  50. if (dwReason == DLL_PROCESS_ATTACH)
  51. {
  52. DEBUG_START;
  53. g_hModuleInstance = hInstance;
  54. _Module.Init(ObjectMap, hInstance);
  55. DisableThreadLibraryCalls(hInstance);
  56. DEBUG_INIT();
  57. _ASSERT( g_pMonitor == NULL );
  58. try
  59. {
  60. g_pMonitor = new CMonitor();
  61. }
  62. catch ( std::bad_alloc& )
  63. {
  64. // nothing we can do about it here
  65. }
  66. }
  67. else if (dwReason == DLL_PROCESS_DETACH)
  68. {
  69. _ASSERT( g_pMonitor != NULL );
  70. delete g_pMonitor;
  71. g_pMonitor = NULL;
  72. DEBUG_TERM();
  73. _Module.Term();
  74. DEBUG_STOP;
  75. }
  76. return TRUE; // ok
  77. }
  78. /////////////////////////////////////////////////////////////////////////////
  79. // Used to determine whether the DLL can be unloaded by OLE
  80. STDAPI DllCanUnloadNow(void)
  81. {
  82. return (_Module.GetLockCount()==0) ? S_OK : S_FALSE;
  83. }
  84. /////////////////////////////////////////////////////////////////////////////
  85. // Returns a class factory to create an object of the requested type
  86. STDAPI DllGetClassObject(REFCLSID rclsid, REFIID riid, LPVOID* ppv)
  87. {
  88. return _Module.GetClassObject(rclsid, riid, ppv);
  89. }
  90. /////////////////////////////////////////////////////////////////////////////
  91. // DllRegisterServer - Adds entries to the system registry
  92. STDAPI DllRegisterServer(void)
  93. {
  94. // registers object, typelib and all interfaces in typelib
  95. return _Module.RegisterServer(TRUE);
  96. }
  97. /////////////////////////////////////////////////////////////////////////////
  98. // DllUnregisterServer - Removes entries from the system registry
  99. STDAPI DllUnregisterServer(void)
  100. {
  101. _Module.UnregisterServer();
  102. return S_OK;
  103. }