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

Windows Kernel

Development Platform:

Visual C++

  1. #include "stdinc.h"
  2. //============================================================================
  3. // This file contains a bunch of Unicode/Ansi thunks to handle calling
  4. // some internal functions that on Windows 95 the strings are Ansi,
  5. // whereas the string on NT are unicode
  6. //============================================================================
  7. // First undefine everything that we are intercepting as to not forward back to us...
  8. #undef PathCleanupSpec
  9. #define THUNKMSG(psz)   TraceMsg(TF_THUNK, "shdv THUNK::%s", psz)
  10. //
  11. //  Now the thunks that allow us to run on Windows 95.
  12. //
  13. //
  14. //
  15. //  This thunks a unicode string to ANSI, but if it's an ordinal, then
  16. //  we just leave it alone.
  17. //
  18. int _AorW_PathCleanupSpec(/*IN OPTIONAL*/ LPCTSTR pszDir, /*IN OUT*/ LPTSTR pszSpec)
  19. {
  20.     THUNKMSG(TEXT("PathCleanupSpec"));
  21.     if (g_bRunningOnNT)
  22.     {
  23.         WCHAR wzDir[MAX_PATH];
  24.         WCHAR wzSpec[MAX_PATH];
  25.         LPWSTR pwszDir = wzDir;
  26.         int iRet;
  27.         if (pszDir)
  28.             SHTCharToUnicode(pszDir, wzDir, ARRAYSIZE(wzDir));
  29.         else
  30.             pwszDir = NULL;
  31.         SHTCharToUnicode(pszSpec, wzSpec, ARRAYSIZE(wzSpec));
  32.         iRet = PathCleanupSpec((LPTSTR)pwszDir, (LPTSTR)wzSpec);
  33.         SHUnicodeToTChar(wzSpec, pszSpec, MAX_PATH);
  34.         return iRet;
  35.     }
  36.     else
  37.     {
  38.         CHAR szDir[MAX_PATH];
  39.         CHAR szSpec[MAX_PATH];
  40.         LPSTR pszDir2 = szDir;
  41.         int iRet;
  42.         if (pszDir)
  43.             SHTCharToAnsi(pszDir, szDir, ARRAYSIZE(szDir));
  44.         else
  45.             pszDir2 = NULL;
  46.         SHTCharToAnsi(pszSpec, szSpec, ARRAYSIZE(szSpec));
  47.         iRet = PathCleanupSpec((LPTSTR)pszDir2, (LPTSTR)szSpec);
  48.         SHAnsiToTChar(szSpec, pszSpec, MAX_PATH);
  49.         return iRet;
  50.     }
  51. }
  52. STDAPI Priv_SHDefExtractIcon(LPCTSTR pszIconFile, int iIndex, UINT uFlags,
  53.                           HICON *phiconLarge, HICON *phiconSmall,
  54.                           UINT nIconSize)
  55. {
  56.     HRESULT hr;
  57.     ASSERT(uFlags == 0);
  58.     //
  59.     // W95 integrated mode supports SHDefExtractIcon.  This supports
  60.     // matching the icon ectracted to the icon color depth.  ExtractIcon
  61.     // doesn't.
  62.     //
  63. #ifndef UNIX
  64.     if ((WhichPlatform() == PLATFORM_INTEGRATED))
  65.     {
  66. #ifdef UNICODE
  67.         if (g_bRunningOnNT) 
  68.         {
  69.             return SHDefExtractIconW(pszIconFile, iIndex, uFlags,
  70.                           phiconLarge, phiconSmall, nIconSize);
  71.         } 
  72.         else 
  73. #endif
  74.         {
  75.             char szIconFile[MAX_PATH];
  76.             SHUnicodeToAnsi(pszIconFile, szIconFile, ARRAYSIZE(szIconFile));
  77.             hr = SHDefExtractIconA(szIconFile, iIndex, uFlags,
  78.                           phiconLarge, phiconSmall, nIconSize);
  79.         }
  80.     }
  81.     else
  82. #endif /* !UNIX */
  83.     {
  84.         char szIconFile[MAX_PATH];
  85.         SHUnicodeToAnsi(pszIconFile, szIconFile, ARRAYSIZE(szIconFile));
  86.         hr = ExtractIconExA(szIconFile, iIndex, phiconLarge,
  87.                            phiconSmall, 1) ? S_OK : E_FAIL;
  88.     }
  89.     return hr;
  90. }