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.

178 lines
3.7 KiB

  1. // BrwCap.cpp : Implementation of DLL Exports.
  2. // Note: Proxy/Stub Information
  3. // To build a separate proxy/stub DLL,
  4. // run nmake -f BrwCapps.mk in the project directory.
  5. #include "stdafx.h"
  6. #include "resource.h"
  7. #include "initguid.h"
  8. #include "BrwCap.h"
  9. #include "BrwCap_i.c"
  10. #include <initguid.h>
  11. #include "BrowCap.h"
  12. #include "CapMap.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. CBrwCapModule _Module;
  20. extern HINSTANCE g_hModuleInstance;
  21. /////////////////////////////////////////////////////////////////////////////
  22. // CPgCntModule methods
  23. //
  24. CBrwCapModule::CBrwCapModule()
  25. : m_pMonitor(NULL),
  26. m_pCapMap(NULL)
  27. {
  28. }
  29. void
  30. CBrwCapModule::Init(
  31. _ATL_OBJMAP_ENTRY* p,
  32. HINSTANCE h )
  33. {
  34. CComModule::Init(p,h);
  35. _ASSERT( m_pMonitor == NULL);
  36. m_pMonitor = new CMonitor();
  37. _ASSERT( m_pCapMap == NULL);
  38. m_pCapMap = new CCapMap();
  39. }
  40. void
  41. CBrwCapModule::Term()
  42. {
  43. _ASSERT( m_pMonitor != NULL);
  44. delete m_pMonitor;
  45. m_pMonitor = NULL;
  46. _ASSERT( m_pCapMap != NULL);
  47. delete m_pCapMap;
  48. m_pCapMap = NULL;
  49. CComModule::Term();
  50. }
  51. LONG
  52. CBrwCapModule::Lock()
  53. {
  54. _ASSERT( m_pMonitor != NULL );
  55. _ASSERT( m_pCapMap != NULL );
  56. CLock l(m_cs);
  57. LONG lc = CComModule::Lock();
  58. ATLTRACE("CBrwCapModule::Lock(%d)\n", lc);
  59. if (lc == 1)
  60. {
  61. m_pCapMap->StartMonitor();
  62. }
  63. return lc;
  64. }
  65. LONG
  66. CBrwCapModule::Unlock()
  67. {
  68. CLock l(m_cs);
  69. LONG lc = CComModule::Unlock();
  70. ATLTRACE("CBrwCapModule::Unlock(%d)\n", lc);
  71. if ( lc == 0 )
  72. {
  73. _ASSERT( m_pMonitor != NULL);
  74. m_pCapMap->StopMonitor();
  75. m_pMonitor->StopAllMonitoring();
  76. _ASSERT( m_pCapMap != NULL);
  77. }
  78. return lc;
  79. }
  80. CMonitor*
  81. CBrwCapModule::Monitor()
  82. {
  83. _ASSERT( m_pMonitor != NULL);
  84. return m_pMonitor;
  85. }
  86. CCapMap*
  87. CBrwCapModule::CapMap()
  88. {
  89. _ASSERT( m_pCapMap != NULL);
  90. return m_pCapMap;
  91. }
  92. BEGIN_OBJECT_MAP(ObjectMap)
  93. OBJECT_ENTRY(CLSID_BrowserCap, CBrowserCap)
  94. END_OBJECT_MAP()
  95. /////////////////////////////////////////////////////////////////////////////
  96. // DLL Entry Point
  97. extern "C"
  98. BOOL WINAPI DllMain(HINSTANCE hInstance, DWORD dwReason, LPVOID /*lpReserved*/)
  99. {
  100. if (dwReason == DLL_PROCESS_ATTACH)
  101. {
  102. DEBUG_START;
  103. g_hModuleInstance = hInstance;
  104. _Module.Init(ObjectMap, hInstance);
  105. DisableThreadLibraryCalls(hInstance);
  106. }
  107. else if (dwReason == DLL_PROCESS_DETACH)
  108. {
  109. ATLTRACE( _T("BrowsCap.dll unloading\n") );
  110. _Module.Term();
  111. DEBUG_STOP;
  112. }
  113. return TRUE; // ok
  114. }
  115. /////////////////////////////////////////////////////////////////////////////
  116. // Used to determine whether the DLL can be unloaded by OLE
  117. STDAPI DllCanUnloadNow(void)
  118. {
  119. return (_Module.GetLockCount()==0) ? S_OK : S_FALSE;
  120. }
  121. /////////////////////////////////////////////////////////////////////////////
  122. // Returns a class factory to create an object of the requested type
  123. STDAPI DllGetClassObject(REFCLSID rclsid, REFIID riid, LPVOID* ppv)
  124. {
  125. return _Module.GetClassObject(rclsid, riid, ppv);
  126. }
  127. /////////////////////////////////////////////////////////////////////////////
  128. // DllRegisterServer - Adds entries to the system registry
  129. STDAPI DllRegisterServer(void)
  130. {
  131. // registers object, typelib and all interfaces in typelib
  132. return _Module.RegisterServer(TRUE);
  133. }
  134. /////////////////////////////////////////////////////////////////////////////
  135. // DllUnregisterServer - Removes entries from the system registry
  136. STDAPI DllUnregisterServer(void)
  137. {
  138. _Module.UnregisterServer();
  139. return S_OK;
  140. }