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.

147 lines
4.0 KiB

  1. // marscore.cpp : Implementation of DLL Exports.
  2. // Note: Proxy/Stub Information
  3. // To merge the proxy/stub code into the object DLL, add the file
  4. // dlldatax.c to the project. Make sure precompiled headers
  5. // are turned off for this file, and add _MERGE_PROXYSTUB to the
  6. // defines for the project.
  7. //
  8. // If you are not running WinNT4.0 or Win95 with DCOM, then you
  9. // need to remove the following define from dlldatax.c
  10. // #define _WIN32_WINNT 0x0400
  11. //
  12. // Further, if you are running MIDL without /Oicf switch, you also
  13. // need to remove the following define from dlldatax.c.
  14. // #define USE_STUBLESS_PROXY
  15. //
  16. // Modify the custom build rule for marscore.idl by adding the following
  17. // files to the Outputs.
  18. // marscore_p.c
  19. // dlldata.c
  20. // To build a separate proxy/stub DLL,
  21. // run nmake -f marscoreps.mk in the project directory.
  22. #include "precomp.h"
  23. #include "mcinc.h"
  24. #include "marswin.h"
  25. #include "external.h"
  26. #include "marsthrd.h"
  27. #ifdef _MERGE_PROXYSTUB
  28. extern "C" HINSTANCE hProxyDll;
  29. #endif
  30. // for the Rating Helper Class Factory
  31. extern GUID CLSID_MarsCustomRatingHelper;
  32. CComModule _Module;
  33. BEGIN_OBJECT_MAP(ObjectMap)
  34. END_OBJECT_MAP()
  35. /////////////////////////////////////////////////////////////////////////////
  36. // DLL Entry Point
  37. extern "C"
  38. BOOL WINAPI DllMain(HINSTANCE hInstance, DWORD dwReason, LPVOID lpReserved)
  39. {
  40. BOOL bResult = TRUE;
  41. lpReserved;
  42. #ifdef _MERGE_PROXYSTUB
  43. if (!PrxDllMain(hInstance, dwReason, lpReserved))
  44. return FALSE;
  45. #endif
  46. if (dwReason == DLL_PROCESS_ATTACH)
  47. {
  48. g_hinst = hInstance;
  49. // We don't pass in the LIBID since we don't register it. Instead,
  50. // "GetMarsTypeLib()" loads and caches it.
  51. _Module.Init(ObjectMap, hInstance, NULL);
  52. DisableThreadLibraryCalls(hInstance);
  53. // Cache a palette handle for use throughout mars
  54. g_hpalHalftone = SHCreateShellPalette( NULL );
  55. // Initialize the global CS object
  56. CMarsGlobalCritSect::InitializeCritSect();
  57. CMarsGlobalsManager::Initialize();
  58. bResult = CThreadData::TlsAlloc();
  59. }
  60. else if (dwReason == DLL_PROCESS_DETACH)
  61. {
  62. _Module.Term();
  63. CThreadData::TlsFree();
  64. CMarsGlobalsManager::Teardown();
  65. // Destroy the global CS object
  66. CMarsGlobalCritSect::TerminateCritSect();
  67. if (g_hpalHalftone)
  68. DeleteObject(g_hpalHalftone);
  69. bResult = TRUE;
  70. }
  71. return bResult;
  72. }
  73. /////////////////////////////////////////////////////////////////////////////
  74. // Used to determine whether the DLL can be unloaded by OLE
  75. STDAPI DllCanUnloadNow(void)
  76. {
  77. #ifdef _MERGE_PROXYSTUB
  78. if (PrxDllCanUnloadNow() != S_OK)
  79. return S_FALSE;
  80. #endif
  81. return (_Module.GetLockCount()==0) ? S_OK : S_FALSE;
  82. }
  83. /////////////////////////////////////////////////////////////////////////////
  84. // Returns a class factory to create an object of the requested type
  85. STDAPI DllGetClassObject(REFCLSID rclsid, REFIID riid, LPVOID* ppv)
  86. {
  87. #ifdef _MERGE_PROXYSTUB
  88. if (PrxDllGetClassObject(rclsid, riid, ppv) == S_OK)
  89. return S_OK;
  90. #endif
  91. return _Module.GetClassObject(rclsid, riid, ppv);
  92. }
  93. #if 0
  94. /////////////////////////////////////////////////////////////////////////////
  95. // DllRegisterServer - Adds entries to the system registry
  96. STDAPI DllRegisterServer(void)
  97. {
  98. #ifdef _MERGE_PROXYSTUB
  99. HRESULT hRes = PrxDllRegisterServer();
  100. if (FAILED(hRes))
  101. return hRes;
  102. #endif
  103. // registers object, typelib and all interfaces in typelib
  104. return _Module.RegisterServer(TRUE);
  105. }
  106. /////////////////////////////////////////////////////////////////////////////
  107. // DllUnregisterServer - Removes entries from the system registry
  108. STDAPI DllUnregisterServer(void)
  109. {
  110. #ifdef _MERGE_PROXYSTUB
  111. PrxDllUnregisterServer();
  112. #endif
  113. return _Module.UnregisterServer(TRUE);
  114. }
  115. #endif //0