utils.cpp
Upload User: xhy777
Upload Date: 2007-02-14
Package Size: 24088k
Code Size: 4k
Category:

Windows Kernel

Development Platform:

Visual C++

  1. #include "stdafx.h"
  2. #pragma hdrstop
  3. #include <mshtml.h>
  4. // This isn't a typical delay load since it's called only if wininet
  5. // is already loaded in memory. Otherwise the call is dropped on the floor.
  6. // Defview did it this way I assume to keep WININET out of first boot time.
  7. BOOL MyInternetSetOption(HANDLE h, DWORD dw1, LPVOID lpv, DWORD dw2)
  8. {
  9.     BOOL bRet = FALSE;
  10.     HMODULE hmod = GetModuleHandle(TEXT("wininet.dll"));
  11.     if (hmod)
  12.     {
  13.         typedef BOOL (*PFNINTERNETSETOPTIONA)(HANDLE h, DWORD dw1, LPVOID lpv, DWORD dw2);
  14.         PFNINTERNETSETOPTIONA fp = (PFNINTERNETSETOPTIONA)GetProcAddress(hmod, "InternetSetOptionA");
  15.         if (fp)
  16.         {
  17.             bRet = fp(h, dw1, lpv, dw2);
  18.         }
  19.     }
  20.     return bRet;
  21. }
  22. // REVIEW: maybe just check (hwnd == GetShellWindow())
  23. STDAPI_(BOOL) IsDesktopWindow(HWND hwnd)
  24. {
  25.     TCHAR szName[80];
  26.     GetClassName(hwnd, szName, ARRAYSIZE(szName));
  27.     if (!lstrcmp(szName, TEXT(STR_DESKTOPCLASS)))
  28.     {
  29.         return hwnd == GetShellWindow();
  30.     }
  31.     return FALSE;
  32. }
  33. // returns:
  34. //      S_OK                all is well, trust the enviornment we are in
  35. //      S_FALSE or 
  36. //      E_ACCESSDENIED      bad... don't expose local machine access
  37. STDAPI IsSafePage(IUnknown *punkSite)
  38. {
  39.     // Return S_FALSE if we don't have a host site since we have no way of doing a 
  40.     // security check.  This is as far as VB 5.0 apps get.
  41.     if (!punkSite)
  42.         return S_FALSE;
  43.     HRESULT hr = E_ACCESSDENIED;
  44.     WCHAR wszPath[MAX_PATH];
  45.     wszPath[0] = 0;
  46.     // ask the browser, for example we are in a .HTM doc
  47.     IBrowserService* pbs;
  48.     if (SUCCEEDED(IUnknown_QueryService(punkSite, SID_SShellBrowser, IID_PPV_ARG(IBrowserService, &pbs))))
  49.     {
  50.         LPITEMIDLIST pidl;
  51.         if (SUCCEEDED(pbs->GetPidl(&pidl)))
  52.         {
  53.             DWORD dwAttribs = SFGAO_FOLDER;
  54.             if (SUCCEEDED(SHGetNameAndFlagsW(pidl, SHGDN_FORPARSING, wszPath, ARRAYSIZE(wszPath), &dwAttribs))
  55.                     && (dwAttribs & SFGAO_FOLDER))   // This is a folder. So, wszPath should be the path for it's webview template
  56.             {
  57.                 // find the template path from webview, for example a .HTT file
  58.                 IOleCommandTarget *pct;
  59.                 if (SUCCEEDED(IUnknown_QueryService(punkSite, SID_DefView, IID_PPV_ARG(IOleCommandTarget, &pct))))
  60.                 {
  61.                     VARIANT vPath;
  62.                     vPath.vt = VT_EMPTY;
  63.                     if (pct->Exec(&CGID_DefView, DVCMDID_GETTEMPLATEDIRNAME, 0, NULL, &vPath) == S_OK)
  64.                     {
  65.                         if (vPath.vt == VT_BSTR && vPath.bstrVal)
  66.                         {
  67.                             DWORD cchPath = ARRAYSIZE(wszPath);
  68.                             if (S_OK != PathCreateFromUrlW(vPath.bstrVal, wszPath, &cchPath, 0))
  69.                             {
  70.                                 // it might not be an URL, in this case it is a file path
  71.                                 StrCpyNW(wszPath, vPath.bstrVal, ARRAYSIZE(wszPath));
  72.                             }
  73.                         }
  74.                         VariantClear(&vPath);
  75.                     }
  76.                     pct->Release();
  77.                 }
  78.             }
  79.             ILFree(pidl);
  80.         }
  81.         pbs->Release();
  82.     }
  83.     else
  84.     {
  85.         ASSERT(0);      // no browser, where are we?
  86.     }
  87.     if (wszPath[0])
  88.         hr = SHRegisterValidateTemplate(wszPath, SHRVT_VALIDATE | SHRVT_PROMPTUSER | SHRVT_REGISTERIFPROMPTOK);
  89.     return hr;
  90. }