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
4.5 KiB

  1. /*
  2. Copyright (c) 1997-2000 Microsoft Corporation
  3. Module Name:
  4. rend.cpp
  5. Abstract:
  6. Implementation of DLL Exports.
  7. Author:
  8. */
  9. // Note: Proxy/Stub Information
  10. // To merge the proxy/stub code into the object DLL, add the file
  11. // dlldatax.c to the project. Make sure precompiled headers
  12. // are turned off for this file, and add _MERGE_PROXYSTUB to the
  13. // defines for the project.
  14. //
  15. // If you are not running WinNT4.0 or Win95 with DCOM, then you
  16. // need to remove the following define from dlldatax.c
  17. // #define _WIN32_WINNT 0x0400
  18. //
  19. // Further, if you are running MIDL without /Oicf switch, you also
  20. // need to remove the following define from dlldatax.c.
  21. // #define USE_STUBLESS_PROXY
  22. //
  23. // Modify the custom build rule for rend.idl by adding the following
  24. // files to the Outputs.
  25. // rend_p.c
  26. // dlldata.c
  27. // To build a separate proxy/stub DLL,
  28. // run nmake -f rendps.mk in the project directory.
  29. #include "stdafx.h"
  30. #include "initguid.h"
  31. #include "rndcommc.h"
  32. #include "rndrend.h"
  33. #include "rndreg.h"
  34. #include "thread.h"
  35. #ifdef _MERGE_PROXYSTUB
  36. #include "dlldatax.h"
  37. extern "C" HINSTANCE hProxyDll;
  38. #endif
  39. // Include the ATL
  40. #ifdef _ATL_STATIC_REGISTRY
  41. #include <statreg.h>
  42. #include <statreg.cpp>
  43. #endif
  44. #include <atlimpl.cpp>
  45. #ifdef DEBUG_HEAPS
  46. // ZoltanS: for heap debugging
  47. #include <crtdbg.h>
  48. #endif // DEBUG_HEAPS
  49. CComModule _Module;
  50. BEGIN_OBJECT_MAP(ObjectMap)
  51. OBJECT_ENTRY(CLSID_Rendezvous, CRendezvous)
  52. END_OBJECT_MAP()
  53. /////////////////////////////////////////////////////////////////////////////
  54. // DLL Entry Point
  55. extern "C"
  56. BOOL WINAPI DllMain(HINSTANCE hInstance, DWORD dwReason, LPVOID lpReserved)
  57. {
  58. lpReserved;
  59. #ifdef _MERGE_PROXYSTUB
  60. if (!PrxDllMain(hInstance, dwReason, lpReserved))
  61. return FALSE;
  62. #endif
  63. if (dwReason == DLL_PROCESS_ATTACH)
  64. {
  65. #ifdef DEBUG_HEAPS
  66. // ZoltanS: turn on leak detection
  67. _CrtSetDbgFlag( _CrtSetDbgFlag(_CRTDBG_REPORT_FLAG) | _CRTDBG_LEAK_CHECK_DF );
  68. // ZoltanS: force a memory leak
  69. char * leak = new char [ 1977 ];
  70. sprintf(leak, "rend.dll NORMAL leak");
  71. leak = NULL;
  72. #endif // DEBUG_HEAPS
  73. _Module.Init(ObjectMap, hInstance);
  74. DisableThreadLibraryCalls(hInstance);
  75. // Randomize for any subsequent calls to rand().
  76. srand( (unsigned) time( NULL ) );
  77. #ifdef MSPLOG
  78. // Register for trace output.
  79. MSPLOGREGISTER(_T("rend"));
  80. #endif // MSPLOG
  81. }
  82. else if (dwReason == DLL_PROCESS_DETACH)
  83. {
  84. #ifdef MSPLOG
  85. // Deregister for trace output.
  86. MSPLOGDEREGISTER();
  87. #endif //MSPLOG
  88. //
  89. // The DLL_PROCESS_DETACH have been called by FreeLibrary
  90. // if is not NULL then the other libraries are already
  91. // unload so we shouldn't have to call them
  92. //
  93. if( lpReserved == NULL )
  94. {
  95. g_RendThread.Shutdown();
  96. }
  97. _Module.Term();
  98. }
  99. return TRUE; // ok
  100. }
  101. /////////////////////////////////////////////////////////////////////////////
  102. // Used to determine whether the DLL can be unloaded by OLE
  103. STDAPI DllCanUnloadNow(void)
  104. {
  105. #ifdef _MERGE_PROXYSTUB
  106. if (PrxDllCanUnloadNow() != S_OK)
  107. return S_FALSE;
  108. #endif
  109. return (_Module.GetLockCount()==0) ? S_OK : S_FALSE;
  110. }
  111. /////////////////////////////////////////////////////////////////////////////
  112. // Returns a class factory to create an object of the requested type
  113. STDAPI DllGetClassObject(REFCLSID rclsid, REFIID riid, LPVOID* ppv)
  114. {
  115. #ifdef _MERGE_PROXYSTUB
  116. if (PrxDllGetClassObject(rclsid, riid, ppv) == S_OK)
  117. return S_OK;
  118. #endif
  119. return _Module.GetClassObject(rclsid, riid, ppv);
  120. }
  121. /////////////////////////////////////////////////////////////////////////////
  122. // DllRegisterServer - Adds entries to the system registry
  123. STDAPI DllRegisterServer(void)
  124. {
  125. #ifdef _MERGE_PROXYSTUB
  126. HRESULT hRes = PrxDllRegisterServer();
  127. if (FAILED(hRes))
  128. return hRes;
  129. #endif
  130. // registers object, typelib and all interfaces in typelib
  131. return _Module.RegisterServer(TRUE);
  132. }
  133. /////////////////////////////////////////////////////////////////////////////
  134. // DllUnregisterServer - Removes entries from the system registry
  135. STDAPI DllUnregisterServer(void)
  136. {
  137. #ifdef _MERGE_PROXYSTUB
  138. PrxDllUnregisterServer();
  139. #endif
  140. _Module.UnregisterServer();
  141. return S_OK;
  142. }