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.

238 lines
7.6 KiB

  1. // DHTMLEd.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 DHTMLEdps.mk in the project directory.
  6. #include "stdafx.h"
  7. #include "resource.h"
  8. #include "initguid.h"
  9. #include "DHTMLEd.h"
  10. #include <TRIEDIID.h>
  11. #include "DHTMLEd_i.c"
  12. #include "DHTMLEdit.h"
  13. #include "DEInsTab.h"
  14. #include "DENames.h"
  15. CComModule _Module;
  16. static void SpikeSharedFileCount ();
  17. BEGIN_OBJECT_MAP(ObjectMap)
  18. OBJECT_ENTRY(CLSID_DHTMLEdit, CDHTMLEdit)
  19. OBJECT_ENTRY(CLSID_DHTMLSafe, CDHTMLSafe)
  20. OBJECT_ENTRY(CLSID_DEInsertTableParam, CDEInsertTableParam)
  21. OBJECT_ENTRY(CLSID_DEGetBlockFmtNamesParam, CDEGetBlockFmtNamesParam)
  22. END_OBJECT_MAP()
  23. /////////////////////////////////////////////////////////////////////////////
  24. //
  25. // Array of CLSIDs as text to be DELETED when registering the control.
  26. // These represent no-longer supported GUIDs for interfaces of the past.
  27. // All GUIDs in this array will be deleted from the HKCR\CLSID section.
  28. // MAINTENANCE NOTE:
  29. // When interfaces get new GUIDs (and the old ones are to be invalidated)
  30. // add the old GUIDs here with appropriate comments.
  31. //
  32. static TCHAR* s_rtszOldClsids [] =
  33. {
  34. TEXT("{683364AF-B37D-11D1-ADC5-006008A5848C}"), // Original Edit control GUID
  35. TEXT("{711054E0-CA70-11D1-8CD2-00A0C959BC0A}"), // Original Safe for Scripting GUID
  36. TEXT("{F8A79F00-DA38-11D1-8CD6-00A0C959BC0A}"), // Intermediate Edit control GUID
  37. TEXT("{F8A79F01-DA38-11D1-8CD6-00A0C959BC0A}") // Intermediate Safe for Scripting GUID
  38. };
  39. /////////////////////////////////////////////////////////////////////////////
  40. //
  41. // Array of CURRENT Interface GUIDS.
  42. // Note that IIDs and CLSIDs are not equivalent!
  43. // ATL fails to unregister these when unregisterin the control.
  44. // MAINTENANCE NOTE:
  45. // When interface GUIDs are changed, update this array.
  46. //
  47. static TCHAR* s_rtszCurrentInterfaces [] =
  48. {
  49. TEXT("{CE04B590-2B1F-11d2-8D1E-00A0C959BC0A}"), // IDHTMLSafe
  50. TEXT("{CE04B591-2B1F-11d2-8D1E-00A0C959BC0A}"), // IDHTMLEdit
  51. TEXT("{47B0DFC6-B7A3-11D1-ADC5-006008A5848C}"), // IDEInsertTableParam
  52. TEXT("{8D91090D-B955-11D1-ADC5-006008A5848C}"), // IDEGetBlockFmtNamesParam
  53. TEXT("{588D5040-CF28-11d1-8CD3-00A0C959BC0A}"), // _DHTMLEditEvents
  54. TEXT("{D1FC78E8-B380-11d1-ADC5-006008A5848C}"), // _DHTMLSafeEvents
  55. };
  56. // MAINTENANCE NOTE:
  57. // If the GUID of the type library changes, update here:
  58. //
  59. static TCHAR* s_tszTypeLibGUID = TEXT("{683364A1-B37D-11D1-ADC5-006008A5848C}");
  60. /////////////////////////////////////////////////////////////////////////////
  61. // DLL Entry Point
  62. //
  63. extern "C"
  64. BOOL WINAPI DllMain(HINSTANCE hInstance, DWORD dwReason, LPVOID /*lpReserved*/)
  65. {
  66. if (dwReason == DLL_PROCESS_ATTACH)
  67. {
  68. _Module.Init(ObjectMap, hInstance);
  69. DisableThreadLibraryCalls(hInstance);
  70. }
  71. else if (dwReason == DLL_PROCESS_DETACH)
  72. {
  73. _Module.Term();
  74. }
  75. return TRUE;
  76. }
  77. /////////////////////////////////////////////////////////////////////////////
  78. // Used to determine whether the DLL can be unloaded by OLE
  79. //
  80. STDAPI DllCanUnloadNow(void)
  81. {
  82. return (_Module.GetLockCount()==0) ? S_OK : S_FALSE;
  83. }
  84. /////////////////////////////////////////////////////////////////////////////
  85. // Returns a class factory to create an object of the requested type
  86. //
  87. STDAPI DllGetClassObject(REFCLSID rclsid, REFIID riid, LPVOID* ppv)
  88. {
  89. return _Module.GetClassObject(rclsid, riid, ppv);
  90. }
  91. /////////////////////////////////////////////////////////////////////////////
  92. // DllRegisterServer - Adds entries to the system registry
  93. //
  94. STDAPI DllRegisterServer(void)
  95. {
  96. HRESULT hr = S_OK;
  97. CRegKey keyClassID;
  98. SpikeSharedFileCount ();
  99. // Unregister old CLSIDs, just in case the user is upgrading without unregistering first.
  100. hr = keyClassID.Open ( HKEY_CLASSES_ROOT, TEXT("CLSID") );
  101. _ASSERTE ( SUCCEEDED ( hr ) );
  102. if ( ERROR_SUCCESS == hr )
  103. {
  104. int ctszOldClsids = sizeof ( s_rtszOldClsids ) / sizeof ( TCHAR* );
  105. for ( int iOldIntf = 0; iOldIntf < ctszOldClsids; iOldIntf++ )
  106. {
  107. hr = keyClassID.RecurseDeleteKey ( s_rtszOldClsids [ iOldIntf ] );
  108. }
  109. hr = keyClassID.Close ();
  110. }
  111. // hr is NOT returned. Any failure deleting possibly non-existant keys is OK.
  112. // registers object, typelib and all interfaces in typelib
  113. return _Module.RegisterServer(TRUE);
  114. }
  115. /////////////////////////////////////////////////////////////////////////////
  116. // DllUnregisterServer - Removes entries from the system registry
  117. //
  118. STDAPI DllUnregisterServer(void)
  119. {
  120. HRESULT hr = S_OK;
  121. HRESULT hrMod = _Module.UnregisterServer();
  122. // Since ATL does not unregister the TypeLib, do it manually.
  123. CRegKey keyTypeLib;
  124. hr = keyTypeLib.Open ( HKEY_CLASSES_ROOT, TEXT("TypeLib") );
  125. if ( ERROR_SUCCESS == hr )
  126. {
  127. hr = keyTypeLib.RecurseDeleteKey ( s_tszTypeLibGUID );
  128. keyTypeLib.Close ();
  129. }
  130. // Delete all current GUIDs from the Interfaces section. ATL fails to do this, too.
  131. CRegKey keyInterface;
  132. hr = keyInterface.Open ( HKEY_CLASSES_ROOT, TEXT("Interface") );
  133. if ( ERROR_SUCCESS == hr )
  134. {
  135. int ctszCurIntf = sizeof ( s_rtszCurrentInterfaces ) / sizeof ( TCHAR* );
  136. for ( int iCurIntf = 0; iCurIntf < ctszCurIntf; iCurIntf++ )
  137. {
  138. hr = keyInterface.RecurseDeleteKey ( s_rtszCurrentInterfaces [ iCurIntf ] );
  139. }
  140. hr = keyInterface.Close ();
  141. }
  142. // DO NOT RETURN the hr from above! It's OK to fail.
  143. return hrMod;
  144. }
  145. // Because we've changed from a shared component to a system component, and we're now
  146. // installed by IE using RollBack rather than reference counting, a serious bug
  147. // occurs if we're installed once under IE4, IE5 is installed, and the original
  148. // product is uninstalled. (We're deleted. Bug 23681.)
  149. // This crude but effective routine spikes our reference count to 10000.
  150. // It doesn't matter so much where we're installed NOW, it matters where the shared
  151. // component was, or might be, installed. Even if it's a different copy, the
  152. // DLL will be unregistered when its reference count is decremented to zero.
  153. //
  154. static void SpikeSharedFileCount ()
  155. {
  156. CRegKey keyShared;
  157. CRegKey keyCurVer;
  158. HRESULT hr = S_OK;
  159. hr = keyCurVer.Open ( HKEY_LOCAL_MACHINE, TEXT("SOFTWARE\\Microsoft\\Windows\\CurrentVersion" ) );
  160. _ASSERTE ( SUCCEEDED ( hr ) );
  161. if ( FAILED ( hr ) )
  162. {
  163. return; // There's nothing we can do.
  164. }
  165. hr = keyShared.Open ( HKEY_LOCAL_MACHINE, TEXT("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\SharedDlls") );
  166. // We expect there to be a SharedDLLs key, but it's possible that there is none.
  167. if ( FAILED ( hr ) )
  168. {
  169. hr = keyShared.Create ( keyCurVer, TEXT("SharedDlls") );
  170. }
  171. _ASSERT ( SUCCEEDED ( hr ) );
  172. if ( SUCCEEDED ( hr ) )
  173. {
  174. TCHAR tszPath[_MAX_PATH];
  175. TCHAR tszMod[_MAX_PATH];
  176. DWORD cchPath = _MAX_PATH;
  177. // Build the string X:\Program Files\Common Files\Microsoft Shared\Triedit\dhtmled.ocx
  178. hr = keyCurVer.QueryValue ( tszPath, TEXT("CommonFilesDir"), &cchPath );
  179. if ( SUCCEEDED ( hr ) )
  180. {
  181. _tcscat ( tszPath, TEXT("\\Microsoft Shared\\Triedit\\") );
  182. // This routine gets the full path name of this DLL. It SHOULD be the same
  183. // as the path we're constructing, but that could change in the future, so
  184. // truncate all but the bare file name.
  185. if ( 0 != GetModuleFileName ( _Module.GetModuleInstance(), tszMod, _MAX_PATH ) )
  186. {
  187. _tcsrev ( tszMod ); // Reverse the string
  188. _tcstok ( tszMod, TEXT("\\") ); // This replaces the first backslash with a \0.
  189. _tcsrev ( tszMod );
  190. _tcscat ( tszPath, tszMod );
  191. hr = keyShared.SetValue ( 10000, tszPath );
  192. }
  193. }
  194. hr = keyShared.Close ();
  195. }
  196. keyCurVer.Close ();
  197. }
  198. // End of DHTMLEd.cpp