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.

184 lines
5.5 KiB

  1. // triedit.cpp : Implementation of DLL Exports.
  2. // Copyright (c)1997-1999 Microsoft Corporation, All Rights Reserved
  3. // Note: Proxy/Stub Information
  4. // To build a separate proxy/stub DLL,
  5. // run nmake -f trieditps.mk in the project directory.
  6. #include "stdafx.h"
  7. #include <initguid.h>
  8. #include "resource.h"
  9. #include "triedit.h"
  10. #include "triedcid.h" //IOleCommandTarget CIDs for TriEdit
  11. #include "htmparse.h"
  12. #include "Document.h"
  13. #include "undo.h"
  14. #include "triedit_i.c"
  15. CComModule _Module;
  16. static void SpikeSharedFileCount ();
  17. BEGIN_OBJECT_MAP(ObjectMap)
  18. OBJECT_ENTRY(CLSID_TriEditDocument, CTriEditDocument)
  19. OBJECT_ENTRY(CLSID_TriEditParse, CTriEditParse)
  20. END_OBJECT_MAP()
  21. /////////////////////////////////////////////////////////////////////////////
  22. // DLL Entry Point
  23. extern "C"
  24. BOOL WINAPI DllMain(HINSTANCE hInstance, DWORD dwReason, LPVOID /*lpReserved*/)
  25. {
  26. if (dwReason == DLL_PROCESS_ATTACH)
  27. {
  28. _Module.Init(ObjectMap, hInstance);
  29. DisableThreadLibraryCalls(hInstance);
  30. }
  31. else if (dwReason == DLL_PROCESS_DETACH)
  32. _Module.Term();
  33. return TRUE; // ok
  34. }
  35. /////////////////////////////////////////////////////////////////////////////
  36. // Used to determine whether the DLL can be unloaded by OLE
  37. STDAPI DllCanUnloadNow(void)
  38. {
  39. return (_Module.GetLockCount()==0) ? S_OK : S_FALSE;
  40. }
  41. /////////////////////////////////////////////////////////////////////////////
  42. // Returns a class factory to create an object of the requested type
  43. STDAPI DllGetClassObject(REFCLSID rclsid, REFIID riid, LPVOID* ppv)
  44. {
  45. return _Module.GetClassObject(rclsid, riid, ppv);
  46. }
  47. /////////////////////////////////////////////////////////////////////////////
  48. // DllRegisterServer - Adds entries to the system registry
  49. STDAPI DllRegisterServer(void)
  50. {
  51. SpikeSharedFileCount ();
  52. // registers object, typelib and all interfaces in typelib
  53. return _Module.RegisterServer(TRUE);
  54. }
  55. /////////////////////////////////////////////////////////////////////////////
  56. // DllUnregisterServer - Removes entries from the system registry
  57. STDAPI DllUnregisterServer(void)
  58. {
  59. HRESULT hr;
  60. ITypeLib * pTypeLib;
  61. TLIBATTR * pTypeLibAttr;
  62. _Module.UnregisterServer();
  63. // Ideally, we want to fix this using ::GetModuleFileName()
  64. // but at this point, we want to keep changes to minimal. (1/14/99)
  65. #ifdef _DEBUG
  66. hr = LoadTypeLib(L"triedit.dll", &pTypeLib);
  67. #else
  68. hr = LoadTypeLib(L"triedit.dll", &pTypeLib);
  69. #endif
  70. _ASSERTE(hr == S_OK);
  71. if (hr == S_OK)
  72. {
  73. if (pTypeLib->GetLibAttr(&pTypeLibAttr) == S_OK)
  74. {
  75. hr = UnRegisterTypeLib(pTypeLibAttr->guid, pTypeLibAttr->wMajorVerNum,
  76. pTypeLibAttr->wMinorVerNum, pTypeLibAttr->lcid,
  77. pTypeLibAttr->syskind);
  78. _ASSERTE(hr == S_OK);
  79. pTypeLib->ReleaseTLibAttr(pTypeLibAttr);
  80. }
  81. pTypeLib->Release();
  82. }
  83. return S_OK;
  84. }
  85. // Because we've changed from a shared component to a system component, and we're now
  86. // installed by IE using RollBack rather than reference counting, a serious bug
  87. // occurs if we're installed once under IE4, IE5 is installed, and the original
  88. // product is uninstalled. (We're deleted. Bug 23681.)
  89. // This crude but effective routine spikes our reference count to 10000.
  90. // It doesn't matter so much where we're installed NOW, it matters where the shared
  91. // component was, or might be, installed. Even if it's a different copy, the
  92. // DLL will be unregistered when its reference count is decremented to zero.
  93. //
  94. static void SpikeSharedFileCount ()
  95. {
  96. CRegKey keyShared;
  97. CRegKey keyCurVer;
  98. HRESULT hr = S_OK;
  99. hr = keyCurVer.Open ( HKEY_LOCAL_MACHINE, TEXT("SOFTWARE\\Microsoft\\Windows\\CurrentVersion" ) );
  100. _ASSERTE ( SUCCEEDED ( hr ) );
  101. if ( FAILED ( hr ) )
  102. {
  103. return; // There's nothing we can do.
  104. }
  105. hr = keyShared.Open ( HKEY_LOCAL_MACHINE, TEXT("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\SharedDlls") );
  106. // We expect there to be a SharedDLLs key, but it's possible that there is none.
  107. if ( FAILED ( hr ) )
  108. {
  109. hr = keyShared.Create ( keyCurVer, TEXT("SharedDlls") );
  110. }
  111. _ASSERT ( SUCCEEDED ( hr ) );
  112. if ( SUCCEEDED ( hr ) )
  113. {
  114. TCHAR tszPath[_MAX_PATH];
  115. TCHAR tszMod[_MAX_PATH];
  116. DWORD cchPath = _MAX_PATH;
  117. // set tszPath to be an empty string in case the QueryValue fails
  118. tszPath[0]=0;
  119. // Build the string X:\Program Files\Common Files\Microsoft Shared\Triedit\dhtmled.ocx
  120. hr = keyCurVer.QueryValue ( tszPath, TEXT("CommonFilesDir"), &cchPath );
  121. if ( SUCCEEDED ( hr ) )
  122. {
  123. _tcscat ( tszPath, TEXT("\\Microsoft Shared\\Triedit\\") );
  124. // This routine gets the full path name of this DLL. It SHOULD be the same
  125. // as the path we're constructing, but that could change in the future, so
  126. // truncate all but the bare file name.
  127. if ( 0 != GetModuleFileName ( _Module.GetModuleInstance(), tszMod, _MAX_PATH ) )
  128. {
  129. _tcsrev ( tszMod ); // Reverse the string
  130. _tcstok ( tszMod, TEXT("\\") ); // This replaces the first backslash with a \0.
  131. _tcsrev ( tszMod );
  132. _tcscat ( tszPath, tszMod );
  133. hr = keyShared.SetValue ( 10000, tszPath );
  134. }
  135. }
  136. hr = keyShared.Close ();
  137. }
  138. keyCurVer.Close ();
  139. }
  140. #ifdef _ATL_STATIC_REGISTRY
  141. #pragma warning(disable: 4100 4189) // Necessary for ia64 build
  142. #include <statreg.h>
  143. #include <statreg.cpp>
  144. #pragma warning(default: 4100 4189) // Necessary for ia64 build
  145. #endif
  146. #include <atlimpl.cpp>