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.

118 lines
2.7 KiB

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