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.

128 lines
2.9 KiB

  1. // AdRot.cpp : Implementation of DLL Exports.
  2. // Note: Proxy/Stub Information
  3. // To build a separate proxy/stub DLL,
  4. // run nmake -f AdRotps.mk in the project directory.
  5. #include "stdafx.h"
  6. #include "resource.h"
  7. #include "initguid.h"
  8. #include "AdRot.h"
  9. #include <time.h>
  10. #include "AdRot_i.c"
  11. #include <initguid.h>
  12. #include "RotObj.h"
  13. #include "Monitor.h"
  14. #ifdef DBG
  15. #undef THIS_FILE
  16. static char THIS_FILE[]=__FILE__;
  17. #define new DEBUG_NEW
  18. #endif
  19. CAdRotModule _Module;
  20. CMonitor* g_pMonitor = NULL;
  21. extern HINSTANCE g_hModuleInstance;
  22. BEGIN_OBJECT_MAP(ObjectMap)
  23. OBJECT_ENTRY(CLSID_AdRotator, CAdRotator)
  24. END_OBJECT_MAP()
  25. LONG
  26. CAdRotModule::Lock()
  27. {
  28. _ASSERT( g_pMonitor != NULL );
  29. return CComModule::Lock();
  30. }
  31. LONG
  32. CAdRotModule::Unlock()
  33. {
  34. LONG lc;
  35. CLock l(m_cs);
  36. if ( ( lc = CComModule::Unlock() ) == 0 )
  37. {
  38. // final unlock
  39. _ASSERT( g_pMonitor != NULL );
  40. g_pMonitor->StopAllMonitoring();
  41. CAdRotator::ClearAdFiles();
  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. srand( static_cast<unsigned int>( time( NULL ) ) );
  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. CAdRotator::ClearAdFiles();
  73. _Module.Term();
  74. _ASSERT( g_pMonitor == NULL );
  75. DEBUG_STOP;
  76. }
  77. return TRUE; // ok
  78. }
  79. /////////////////////////////////////////////////////////////////////////////
  80. // Used to determine whether the DLL can be unloaded by OLE
  81. STDAPI DllCanUnloadNow(void)
  82. {
  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. return _Module.GetClassObject(rclsid, riid, ppv);
  90. }
  91. /////////////////////////////////////////////////////////////////////////////
  92. // DllRegisterServer - Adds entries to the system registry
  93. STDAPI DllRegisterServer(void)
  94. {
  95. // registers object, typelib and all interfaces in typelib
  96. return _Module.RegisterServer(TRUE);
  97. }
  98. /////////////////////////////////////////////////////////////////////////////
  99. // DllUnregisterServer - Removes entries from the system registry
  100. STDAPI DllUnregisterServer(void)
  101. {
  102. _Module.UnregisterServer();
  103. return S_OK;
  104. }