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.

208 lines
6.1 KiB

  1. // webvw.cpp : Main Web View File
  2. // contains implementation of DLL Exports; debug info, etc.
  3. #include "priv.h"
  4. #include "wvcoord.h"
  5. #include "fldricon.h"
  6. #define DECL_CRTFREE
  7. #include <crtfree.h>
  8. STDAPI RegisterStuff(HINSTANCE hinstWebvw);
  9. // from install.cpp
  10. HRESULT SetFileAndFolderAttribs(HINSTANCE hInstResource);
  11. CComModule _Module;
  12. BEGIN_OBJECT_MAP(ObjectMap)
  13. OBJECT_ENTRY(CLSID_WebView, CComObject<CWebViewCoord>) // W2K
  14. OBJECT_ENTRY(CLSID_WebViewOld, CComObject<CWebViewCoord>) // W2K
  15. OBJECT_ENTRY(CLSID_ThumbCtl, CComObject<CThumbCtl>) // W2K
  16. OBJECT_ENTRY(CLSID_ThumbCtlOld, CComObject<CThumbCtl>) // W2K
  17. OBJECT_ENTRY(CLSID_WebViewFolderIcon, CComObject<CWebViewFolderIcon>) // W2K
  18. OBJECT_ENTRY(CLSID_WebViewFolderIconOld, CComObject<CWebViewFolderIcon>) // W2K
  19. END_OBJECT_MAP()
  20. /////////////////////////////////////////////////////////////////////////////
  21. // DLL Entry Point
  22. STDAPI_(BOOL) DllMain(HINSTANCE hInstance, DWORD dwReason, LPVOID /*lpReserved*/)
  23. {
  24. if (dwReason == DLL_PROCESS_ATTACH)
  25. {
  26. #ifdef DEBUG
  27. CcshellGetDebugFlags();
  28. #endif
  29. _Module.Init(ObjectMap, hInstance);
  30. DisableThreadLibraryCalls(hInstance);
  31. SHFusionInitializeFromModule(hInstance);
  32. }
  33. else if (dwReason == DLL_PROCESS_DETACH)
  34. {
  35. SHFusionUninitialize();
  36. _Module.Term();
  37. }
  38. return TRUE; // ok
  39. }
  40. /////////////////////////////////////////////////////////////////////////////
  41. // Used to determine whether the DLL can be unloaded by OLE
  42. STDAPI DllCanUnloadNow(void)
  43. {
  44. return (_Module.GetLockCount()==0) ? S_OK : S_FALSE;
  45. }
  46. /////////////////////////////////////////////////////////////////////////////
  47. // Returns a class factory to create an object of the requested type
  48. STDAPI DllGetClassObject(REFCLSID rclsid, REFIID riid, LPVOID* ppv)
  49. {
  50. return _Module.GetClassObject(rclsid, riid, ppv);
  51. }
  52. typedef int (* PFNLOADSTRING) (HINSTANCE, UINT, LPTSTR, int);
  53. // This is used so we aren't forced to call MLLoadString
  54. int NonMLLoadString(HINSTANCE hinst, UINT uID, LPTSTR psz, int cch)
  55. {
  56. static PFNLOADSTRING s_pfn = (PFNLOADSTRING)-1;
  57. if (s_pfn == (PFNLOADSTRING)-1)
  58. {
  59. s_pfn = (PFNLOADSTRING) GetProcAddress(GetModuleHandle(TEXT("USER32.DLL")), "LoadStringW");
  60. }
  61. if (s_pfn)
  62. {
  63. return s_pfn(hinst, uID, psz, cch);
  64. }
  65. return 0;
  66. }
  67. HRESULT ConvertDefaultWallpaper(void)
  68. {
  69. HRESULT hr;
  70. if (!IsOS(OS_WOW6432))
  71. {
  72. hr = E_OUTOFMEMORY;
  73. // We convert the default wallpaper (default.jpg) to a .bmp since user can't handle .jpg's and
  74. // we don't want to force Active Desktop on.
  75. TCHAR szPathSrc[MAX_PATH];
  76. TCHAR szPathDest[MAX_PATH];
  77. if (GetWindowsDirectory(szPathSrc, ARRAYSIZE(szPathSrc)))
  78. {
  79. int cchCopied;
  80. TCHAR szDisplayName[MAX_PATH];
  81. UINT uID;
  82. // we have different default wallpaper files for per vs. pro vs. server
  83. if (IsOS(OS_ANYSERVER))
  84. {
  85. uID = IDS_WALLPAPER_LOCNAME_SRV;
  86. }
  87. else if (IsOS(OS_PERSONAL))
  88. {
  89. uID = IDS_WALLPAPER_LOCNAME_PER;
  90. }
  91. else
  92. {
  93. // use the professional wallpaper
  94. uID = IDS_WALLPAPER_LOCNAME;
  95. }
  96. // we want to call the non-MUI loadstring function here since the wallpaper is a file on disk that is always localized
  97. // in the system default local, not whatever the current users local is
  98. cchCopied = NonMLLoadString(_Module.GetResourceInstance(), uID, szDisplayName, ARRAYSIZE(szDisplayName));
  99. if (cchCopied)
  100. {
  101. PathAppend(szPathSrc, TEXT("Web\\Wallpaper\\"));
  102. StrCpyN(szPathDest, szPathSrc, ARRAYSIZE(szPathDest));
  103. PathAppend(szPathSrc, TEXT("default.jpg"));
  104. PathAppend(szPathDest, szDisplayName);
  105. StrCatBuff(szPathDest, TEXT(".bmp"), ARRAYSIZE(szPathDest));
  106. if (PathFileExists(szPathSrc))
  107. {
  108. hr = SHConvertGraphicsFile(szPathSrc, szPathDest, SHCGF_REPLACEFILE);
  109. if (SUCCEEDED(hr))
  110. {
  111. DeleteFile(szPathSrc);
  112. }
  113. }
  114. else
  115. {
  116. hr = S_OK;
  117. }
  118. }
  119. }
  120. }
  121. else
  122. {
  123. // don't try to convert the wallpaper if we are wow6432 since the 64 bit guy already
  124. // did it for us and if we try it will end up deleting it!!
  125. hr = S_OK;
  126. }
  127. return hr;
  128. }
  129. /////////////////////////////////////////////////////////////////////////////
  130. // DllRegisterServer - Adds entries to the system registry
  131. STDAPI DllRegisterServer(void)
  132. {
  133. // setup attribs on system files/folders
  134. HRESULT hrRet = SetFileAndFolderAttribs(_Module.GetResourceInstance());
  135. TCHAR szWinPath[MAX_PATH];
  136. GetWindowsDirectory(szWinPath, ARRAYSIZE(szWinPath));
  137. struct _ATL_REGMAP_ENTRY regMap[] =
  138. {
  139. {OLESTR("windir"), szWinPath}, // subsitute %windir% for registry
  140. {0, 0}
  141. };
  142. HRESULT hr = RegisterStuff(_Module.GetResourceInstance());
  143. if (SUCCEEDED(hrRet))
  144. {
  145. hrRet = hr;
  146. }
  147. ConvertDefaultWallpaper();
  148. // registers object, typelib and all interfaces in typelib
  149. hr = _Module.RegisterServer(TRUE);
  150. return SUCCEEDED(hrRet) ? hr : hrRet;
  151. }
  152. STDAPI DllInstall(BOOL fInstall, LPCWSTR pszCmdLine)
  153. {
  154. HRESULT hr = E_FAIL;
  155. if (pszCmdLine)
  156. {
  157. ASSERTMSG(StrStrIW(pszCmdLine, L"/RES=") == NULL, "webvw!DllInstall : passed old MUI command (no longer supported)");
  158. }
  159. return hr;
  160. }
  161. /////////////////////////////////////////////////////////////////////////////
  162. // DllUnregisterServer - Removes entries from the system registry
  163. STDAPI DllUnregisterServer(void)
  164. {
  165. _Module.UnregisterServer();
  166. return S_OK;
  167. }