ole2dup2.c
Upload User: xhy777
Upload Date: 2007-02-14
Package Size: 24088k
Code Size: 2k
Category:

Windows Kernel

Development Platform:

Visual C++

  1. #include "shellprv.h"
  2. #pragma  hdrstop
  3. // NOTE: the STRRET_WSTR pOleStr gets freed, so don't try to use it later
  4. STDAPI_(BOOL) StrRetToStrN(LPTSTR pszOut, UINT cchOut, STRRET *pStrRet, LPCITEMIDLIST pidl)
  5. {
  6.     return SUCCEEDED(StrRetToBuf(pStrRet, pidl, pszOut, cchOut));
  7. }
  8. STDAPI_(int) OleStrToStrN(LPTSTR pszOut, int cchOut, LPCWSTR pwsz, int cchWideChar)
  9. {
  10.     int cchOutput;
  11. #ifdef UNICODE
  12.     VDATEINPUTBUF(pszOut, WCHAR, cchOut);
  13.     if (cchOut > cchWideChar && -1 != cchWideChar)
  14.         cchOut = cchWideChar;
  15.     cchOutput = cchOut;
  16.     while (cchOut)
  17.     {
  18.         if ((*pszOut++ = *pwsz++) == 0)
  19.             return cchOutput - cchOut + 1;
  20.         cchOut--;
  21.     }
  22.     if (-1 == cchWideChar)
  23.         pszOut--;              // Make room for the null 
  24.     *pszOut = 0;
  25.     return cchOutput;
  26. #else
  27.     VDATEINPUTBUF(pszOut, CHAR, cchOut);
  28.     cchOutput = WideCharToMultiByte(CP_ACP, 0, pwsz, cchWideChar, pszOut, cchOut, NULL, NULL);
  29.     if (cchOutput && (cchOutput == cchOut))
  30.         cchOutput--;
  31.     pszOut[cchOutput] = 0;
  32.     return cchOutput;
  33. #endif // UNICODE
  34. }
  35. STDAPI_(int) StrToOleStrN(LPWSTR pwszOut, int cchOut, LPCTSTR psz, int cchIn)
  36. {
  37.     int cchOutput;
  38. #ifdef UNICODE
  39.     VDATEINPUTBUF(pwszOut, WCHAR, cchOut);
  40.     if (cchOut > cchIn)
  41.         cchOut = cchIn;
  42.     cchOutput = cchOut;
  43.     while (--cchOut)
  44.     {
  45.         if ((*pwszOut++ = *psz++) == 0)
  46.             return cchOutput - cchOut + 1;
  47.     }
  48.     *pwszOut = 0;
  49.     return cchOutput;
  50. #else
  51.     VDATEINPUTBUF(pwszOut, WCHAR, cchOut);
  52.     cchOutput = MultiByteToWideChar(CP_ACP, 0, psz, cchIn, pwszOut, cchOut);
  53.     if (cchOutput && (cchOutput == cchOut))
  54.         cchOutput--;
  55.     pwszOut[cchOutput] = 0;
  56.     return cchOutput;
  57. #endif
  58. }
  59. // bogus export, too scared to remove it
  60. STDAPI_(int) StrToOleStr(LPWSTR pwszOut, LPCTSTR psz)
  61. {
  62.     VDATEINPUTBUF(pwszOut, WCHAR, MAX_PATH);
  63.     return SHTCharToUnicode(psz, pwszOut, MAX_PATH);
  64. }