Source code of Windows XP (NT5)
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.

180 lines
5.3 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. // We convert the default wallpaper (default.jpg) to a .bmp since user can't handle .jpg's and
  70. // we don't want to force Active Desktop on.
  71. TCHAR szPathSrc[MAX_PATH];
  72. TCHAR szPathDest[MAX_PATH];
  73. HRESULT hr = E_OUTOFMEMORY;
  74. if (GetWindowsDirectory(szPathSrc, ARRAYSIZE(szPathSrc)))
  75. {
  76. int cchCopied;
  77. TCHAR szDisplayName[MAX_PATH];
  78. // we want to call the non-MUI loadstring function here since the wallpaper is a file on disk that is always localized
  79. // in the system default local, not whatever the current users local is
  80. if (IsOS(OS_PERSONAL))
  81. {
  82. // we have a different wallpaper name on per (Bliss.bmp vs Windows XP.jpg)
  83. cchCopied = NonMLLoadString(_Module.GetResourceInstance(), IDS_WALLPAPER_LOCNAME_PER, szDisplayName, ARRAYSIZE(szDisplayName));
  84. }
  85. else
  86. {
  87. cchCopied = NonMLLoadString(_Module.GetResourceInstance(), IDS_WALLPAPER_LOCNAME, szDisplayName, ARRAYSIZE(szDisplayName));
  88. }
  89. if (cchCopied)
  90. {
  91. PathAppend(szPathSrc, TEXT("Web\\Wallpaper\\"));
  92. StrCpyN(szPathDest, szPathSrc, ARRAYSIZE(szPathDest));
  93. PathAppend(szPathSrc, TEXT("default.jpg"));
  94. PathAppend(szPathDest, szDisplayName);
  95. StrCatBuff(szPathDest, TEXT(".bmp"), ARRAYSIZE(szPathDest));
  96. hr = SHConvertGraphicsFile(szPathSrc, szPathDest, SHCGF_REPLACEFILE);
  97. if (SUCCEEDED(hr))
  98. {
  99. DeleteFile(szPathSrc);
  100. }
  101. }
  102. }
  103. return hr;
  104. }
  105. /////////////////////////////////////////////////////////////////////////////
  106. // DllRegisterServer - Adds entries to the system registry
  107. STDAPI DllRegisterServer(void)
  108. {
  109. // setup attribs on system files/folders
  110. HRESULT hrRet = SetFileAndFolderAttribs(_Module.GetResourceInstance());
  111. TCHAR szWinPath[MAX_PATH];
  112. GetWindowsDirectory(szWinPath, ARRAYSIZE(szWinPath));
  113. struct _ATL_REGMAP_ENTRY regMap[] =
  114. {
  115. {OLESTR("windir"), szWinPath}, // subsitute %windir% for registry
  116. {0, 0}
  117. };
  118. HRESULT hr = RegisterStuff(_Module.GetResourceInstance());
  119. if (SUCCEEDED(hrRet))
  120. {
  121. hrRet = hr;
  122. }
  123. ConvertDefaultWallpaper();
  124. // registers object, typelib and all interfaces in typelib
  125. hr = _Module.RegisterServer(TRUE);
  126. return SUCCEEDED(hrRet) ? hr : hrRet;
  127. }
  128. STDAPI DllInstall(BOOL fInstall, LPCWSTR pszCmdLine)
  129. {
  130. HRESULT hr = E_FAIL;
  131. if (pszCmdLine)
  132. {
  133. ASSERTMSG(StrStrIW(pszCmdLine, L"/RES=") == NULL, "webvw!DllInstall : passed old MUI command (no longer supported)");
  134. }
  135. return hr;
  136. }
  137. /////////////////////////////////////////////////////////////////////////////
  138. // DllUnregisterServer - Removes entries from the system registry
  139. STDAPI DllUnregisterServer(void)
  140. {
  141. _Module.UnregisterServer();
  142. return S_OK;
  143. }