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.

142 lines
4.0 KiB

  1. //+-------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. //
  5. // Copyright (C) Microsoft Corporation, 1999 - 1999
  6. //
  7. // File: mmcshext.cpp
  8. //
  9. //--------------------------------------------------------------------------
  10. // mmcshext.cpp : Implementation of DLL Exports.
  11. // Note: Proxy/Stub Information
  12. // To build a separate proxy/stub DLL,
  13. // run nmake -f mmcshextps.mk in the project directory.
  14. #include "stdafx.h"
  15. #include "resource.h"
  16. #include <initguid.h>
  17. #include <shlobj.h>
  18. #include <shlguid.h>
  19. #include "Extract.h"
  20. #include "hhcwrap.h"
  21. #include "picon.h"
  22. #include "modulepath.h"
  23. #include <atlimpl.cpp>
  24. CComModule _Module;
  25. static void RemovePathFromInProcServerEntry (REFCLSID rclsid);
  26. BEGIN_OBJECT_MAP(ObjectMap)
  27. OBJECT_ENTRY(CLSID_ExtractIcon, CExtractIcon)
  28. OBJECT_ENTRY(CLSID_HHCollectionWrapper, CHHCollectionWrapper)
  29. END_OBJECT_MAP()
  30. /////////////////////////////////////////////////////////////////////////////
  31. // DLL Entry Point
  32. extern "C"
  33. BOOL WINAPI DllMain(HINSTANCE hInstance, DWORD dwReason, LPVOID /*lpReserved*/)
  34. {
  35. if (dwReason == DLL_PROCESS_ATTACH)
  36. {
  37. _Module.Init(ObjectMap, hInstance);
  38. DisableThreadLibraryCalls(hInstance);
  39. }
  40. else if (dwReason == DLL_PROCESS_DETACH)
  41. _Module.Term();
  42. return TRUE; // ok
  43. }
  44. /////////////////////////////////////////////////////////////////////////////
  45. // Used to determine whether the DLL can be unloaded by OLE
  46. STDAPI DllCanUnloadNow(void)
  47. {
  48. return (_Module.GetLockCount()==0) ? S_OK : S_FALSE;
  49. }
  50. /////////////////////////////////////////////////////////////////////////////
  51. // Returns a class factory to create an object of the requested type
  52. STDAPI DllGetClassObject(REFCLSID rclsid, REFIID riid, LPVOID* ppv)
  53. {
  54. return _Module.GetClassObject(rclsid, riid, ppv);
  55. }
  56. /////////////////////////////////////////////////////////////////////////////
  57. // DllRegisterServer - Adds entries to the system registry
  58. STDAPI DllRegisterServer(void)
  59. {
  60. // registers object, typelib and all interfaces in typelib
  61. HRESULT hr = _Module.RegisterServer(FALSE);
  62. if (hr == S_OK)
  63. {
  64. // remove full module path that ATL adds by default
  65. RemovePathFromInProcServerEntry(CLSID_ExtractIcon);
  66. RemovePathFromInProcServerEntry(CLSID_HHCollectionWrapper);
  67. }
  68. return hr;
  69. }
  70. /////////////////////////////////////////////////////////////////////////////
  71. // DllUnregisterServer - Removes entries from the system registry
  72. STDAPI DllUnregisterServer(void)
  73. {
  74. return _Module.UnregisterServer();
  75. }
  76. static void RemovePathFromInProcServerEntry (REFCLSID rclsid)
  77. {
  78. // Convert the CLSID to a string
  79. USES_CONVERSION;
  80. LPOLESTR lpOleStr;
  81. HRESULT hr = StringFromCLSID (rclsid, &lpOleStr);
  82. if (FAILED(hr))
  83. return;
  84. if (lpOleStr != NULL)
  85. {
  86. // Re-register the InProcServer key without the path
  87. TCHAR szSubKey[MAX_PATH];
  88. _tcscpy (szSubKey, _T("CLSID\\"));
  89. _tcscat (szSubKey, OLE2T(lpOleStr));
  90. _tcscat (szSubKey, _T("\\InprocServer32"));
  91. CoTaskMemFree(lpOleStr);
  92. ::ATL::CRegKey regkey;
  93. long lRes = regkey.Open(HKEY_CLASSES_ROOT, szSubKey);
  94. ASSERT(lRes == ERROR_SUCCESS);
  95. if (lRes == ERROR_SUCCESS)
  96. {
  97. CStr strPath = _T("mmcshext.dll");
  98. // try to get absolute path value
  99. CStr strAbsolute = CModulePath::MakeAbsoluteModulePath( strPath );
  100. if ( strAbsolute.GetLength() > 0 )
  101. strPath = strAbsolute;
  102. // see what type of value we need to put
  103. DWORD dwValueType = CModulePath::PlatformSupports_REG_EXPAND_SZ_Values() ?
  104. REG_EXPAND_SZ : REG_SZ;
  105. lRes = RegSetValueEx( regkey, NULL, 0, dwValueType,
  106. (CONST BYTE *)((LPCTSTR)strPath),
  107. (strPath.GetLength() + 1) * sizeof(TCHAR) );
  108. ASSERT(lRes == ERROR_SUCCESS);
  109. }
  110. }
  111. }