2002-03-10 00:29:33 +01:00
|
|
|
/*
|
|
|
|
* Shlwapi string functions
|
|
|
|
*
|
|
|
|
* Copyright 1998 Juergen Schmied
|
2002-08-20 01:57:27 +02:00
|
|
|
* Copyright 2002 Jon Griffiths
|
2002-03-10 00:29:33 +01:00
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
2006-05-18 14:49:52 +02:00
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
|
2002-03-10 00:29:33 +01:00
|
|
|
*/
|
|
|
|
|
2002-09-20 21:41:08 +02:00
|
|
|
#include <math.h>
|
2003-09-06 01:08:26 +02:00
|
|
|
#include <stdarg.h>
|
2000-07-26 19:51:32 +02:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
2003-01-07 21:36:20 +01:00
|
|
|
#define NONAMELESSUNION
|
2015-03-20 09:50:41 +01:00
|
|
|
|
2003-09-06 01:08:26 +02:00
|
|
|
#include "windef.h"
|
2000-09-26 02:00:55 +02:00
|
|
|
#include "winbase.h"
|
2003-07-22 05:13:22 +02:00
|
|
|
#define NO_SHLWAPI_REG
|
2001-12-11 01:30:17 +01:00
|
|
|
#define NO_SHLWAPI_STREAM
|
2000-09-13 22:28:31 +02:00
|
|
|
#include "shlwapi.h"
|
2003-09-06 01:08:26 +02:00
|
|
|
#include "wingdi.h"
|
|
|
|
#include "winuser.h"
|
2000-09-26 02:00:55 +02:00
|
|
|
#include "shlobj.h"
|
2007-03-28 13:13:54 +02:00
|
|
|
#include "mlang.h"
|
2004-02-17 23:48:56 +01:00
|
|
|
#include "ddeml.h"
|
2002-03-10 00:29:33 +01:00
|
|
|
#include "wine/debug.h"
|
2000-07-26 19:51:32 +02:00
|
|
|
|
2006-08-17 22:44:29 +02:00
|
|
|
#include "resource.h"
|
|
|
|
|
2002-03-10 00:29:33 +01:00
|
|
|
WINE_DEFAULT_DEBUG_CHANNEL(shell);
|
2000-07-26 19:51:32 +02:00
|
|
|
|
2006-08-17 22:44:29 +02:00
|
|
|
extern HINSTANCE shlwapi_hInstance;
|
2004-02-17 23:48:56 +01:00
|
|
|
|
2007-06-25 14:01:28 +02:00
|
|
|
static HRESULT _SHStrDupAA(LPCSTR,LPSTR*);
|
|
|
|
static HRESULT _SHStrDupAW(LPCWSTR,LPSTR*);
|
2002-08-07 01:50:27 +02:00
|
|
|
|
2019-06-20 09:12:29 +02:00
|
|
|
DWORD WINAPI SHTruncateString(LPSTR lpStr, DWORD size);
|
2006-08-21 23:40:36 +02:00
|
|
|
|
2006-09-27 20:27:37 +02:00
|
|
|
static void FillNumberFmt(NUMBERFMTW *fmt, LPWSTR decimal_buffer, int decimal_bufwlen,
|
|
|
|
LPWSTR thousand_buffer, int thousand_bufwlen)
|
2006-08-22 16:52:52 +02:00
|
|
|
{
|
|
|
|
WCHAR grouping[64];
|
|
|
|
WCHAR *c;
|
|
|
|
|
|
|
|
GetLocaleInfoW(LOCALE_USER_DEFAULT, LOCALE_ILZERO|LOCALE_RETURN_NUMBER, (LPWSTR)&fmt->LeadingZero, sizeof(fmt->LeadingZero)/sizeof(WCHAR));
|
|
|
|
GetLocaleInfoW(LOCALE_USER_DEFAULT, LOCALE_INEGNUMBER|LOCALE_RETURN_NUMBER, (LPWSTR)&fmt->LeadingZero, sizeof(fmt->NegativeOrder)/sizeof(WCHAR));
|
|
|
|
fmt->NumDigits = 0;
|
2006-09-27 20:27:37 +02:00
|
|
|
GetLocaleInfoW(LOCALE_USER_DEFAULT, LOCALE_SDECIMAL, decimal_buffer, decimal_bufwlen);
|
|
|
|
GetLocaleInfoW(LOCALE_USER_DEFAULT, LOCALE_STHOUSAND, thousand_buffer, thousand_bufwlen);
|
2006-08-22 16:52:52 +02:00
|
|
|
fmt->lpThousandSep = thousand_buffer;
|
|
|
|
fmt->lpDecimalSep = decimal_buffer;
|
2006-09-27 20:27:37 +02:00
|
|
|
|
2006-08-22 16:52:52 +02:00
|
|
|
/*
|
|
|
|
* Converting grouping string to number as described on
|
|
|
|
* http://blogs.msdn.com/oldnewthing/archive/2006/04/18/578251.aspx
|
|
|
|
*/
|
|
|
|
fmt->Grouping = 0;
|
2018-09-15 00:10:31 +02:00
|
|
|
GetLocaleInfoW(LOCALE_USER_DEFAULT, LOCALE_SGROUPING, grouping, ARRAY_SIZE(grouping));
|
2006-08-22 16:52:52 +02:00
|
|
|
for (c = grouping; *c; c++)
|
|
|
|
if (*c >= '0' && *c < '9')
|
|
|
|
{
|
|
|
|
fmt->Grouping *= 10;
|
|
|
|
fmt->Grouping += *c - '0';
|
|
|
|
}
|
|
|
|
|
|
|
|
if (fmt->Grouping % 10 == 0)
|
|
|
|
fmt->Grouping /= 10;
|
|
|
|
else
|
|
|
|
fmt->Grouping *= 10;
|
|
|
|
}
|
|
|
|
|
2006-08-21 23:40:36 +02:00
|
|
|
/*************************************************************************
|
|
|
|
* FormatInt [internal]
|
|
|
|
*
|
|
|
|
* Format an integer according to the current locale
|
|
|
|
*
|
|
|
|
* RETURNS
|
2012-03-08 14:35:56 +01:00
|
|
|
* The number of characters written on success or 0 on failure
|
2006-08-21 23:40:36 +02:00
|
|
|
*/
|
|
|
|
static int FormatInt(LONGLONG qdwValue, LPWSTR pszBuf, int cchBuf)
|
|
|
|
{
|
|
|
|
NUMBERFMTW fmt;
|
|
|
|
WCHAR decimal[8], thousand[8];
|
|
|
|
WCHAR buf[24];
|
|
|
|
WCHAR *c;
|
|
|
|
BOOL neg = (qdwValue < 0);
|
|
|
|
|
2018-09-15 00:10:31 +02:00
|
|
|
FillNumberFmt(&fmt, decimal, ARRAY_SIZE(decimal), thousand, ARRAY_SIZE(thousand));
|
2006-09-27 20:27:37 +02:00
|
|
|
|
2006-08-21 23:40:36 +02:00
|
|
|
c = &buf[24];
|
|
|
|
*(--c) = 0;
|
|
|
|
do
|
|
|
|
{
|
|
|
|
*(--c) = '0' + (qdwValue%10);
|
|
|
|
qdwValue /= 10;
|
|
|
|
} while (qdwValue > 0);
|
|
|
|
if (neg)
|
|
|
|
*(--c) = '-';
|
|
|
|
|
|
|
|
return GetNumberFormatW(LOCALE_USER_DEFAULT, 0, c, &fmt, pszBuf, cchBuf);
|
|
|
|
}
|
|
|
|
|
2006-08-22 16:52:52 +02:00
|
|
|
/*************************************************************************
|
|
|
|
* FormatDouble [internal]
|
|
|
|
*
|
|
|
|
* Format an integer according to the current locale. Prints the specified number of digits
|
|
|
|
* after the decimal point
|
|
|
|
*
|
|
|
|
* RETURNS
|
2012-03-08 14:35:56 +01:00
|
|
|
* The number of characters written on success or 0 on failure
|
2006-08-22 16:52:52 +02:00
|
|
|
*/
|
|
|
|
static int FormatDouble(double value, int decimals, LPWSTR pszBuf, int cchBuf)
|
|
|
|
{
|
|
|
|
static const WCHAR flfmt[] = {'%','f',0};
|
|
|
|
WCHAR buf[64];
|
|
|
|
NUMBERFMTW fmt;
|
|
|
|
WCHAR decimal[8], thousand[8];
|
|
|
|
|
2019-06-20 09:13:05 +02:00
|
|
|
swprintf(buf, 64, flfmt, value);
|
2006-08-22 16:52:52 +02:00
|
|
|
|
2018-09-15 00:10:31 +02:00
|
|
|
FillNumberFmt(&fmt, decimal, ARRAY_SIZE(decimal), thousand, ARRAY_SIZE(thousand));
|
2006-08-22 16:52:52 +02:00
|
|
|
fmt.NumDigits = decimals;
|
|
|
|
return GetNumberFormatW(LOCALE_USER_DEFAULT, 0, buf, &fmt, pszBuf, cchBuf);
|
|
|
|
}
|
|
|
|
|
2001-12-01 01:37:12 +01:00
|
|
|
/*************************************************************************
|
2019-06-20 09:12:29 +02:00
|
|
|
* StrCatW [SHLWAPI.@]
|
2002-08-20 01:57:27 +02:00
|
|
|
*
|
2019-06-20 09:12:29 +02:00
|
|
|
* Concatenate two strings.
|
2002-08-20 01:57:27 +02:00
|
|
|
*
|
|
|
|
* PARAMS
|
2019-06-20 09:12:29 +02:00
|
|
|
* lpszStr [O] Initial string
|
|
|
|
* lpszSrc [I] String to concatenate
|
2002-08-20 01:57:27 +02:00
|
|
|
*
|
|
|
|
* RETURNS
|
2019-06-20 09:12:29 +02:00
|
|
|
* lpszStr.
|
2002-08-20 01:57:27 +02:00
|
|
|
*/
|
2019-06-20 09:12:29 +02:00
|
|
|
LPWSTR WINAPI StrCatW(LPWSTR lpszStr, LPCWSTR lpszSrc)
|
2002-08-20 01:57:27 +02:00
|
|
|
{
|
2019-06-20 09:12:29 +02:00
|
|
|
TRACE("(%s,%s)\n", debugstr_w(lpszStr), debugstr_w(lpszSrc));
|
2002-08-20 01:57:27 +02:00
|
|
|
|
2019-06-20 09:12:29 +02:00
|
|
|
if (lpszStr && lpszSrc)
|
2019-06-20 09:13:05 +02:00
|
|
|
lstrcatW(lpszStr, lpszSrc);
|
2019-06-20 09:12:29 +02:00
|
|
|
return lpszStr;
|
2002-08-20 01:57:27 +02:00
|
|
|
}
|
2001-11-06 00:55:36 +01:00
|
|
|
|
2000-07-26 19:51:32 +02:00
|
|
|
/*************************************************************************
|
2019-06-20 09:12:29 +02:00
|
|
|
* StrCpyW [SHLWAPI.@]
|
2000-07-26 19:51:32 +02:00
|
|
|
*
|
2019-06-20 09:12:29 +02:00
|
|
|
* Copy a string to another string.
|
2000-07-26 19:51:32 +02:00
|
|
|
*
|
2002-08-20 01:57:27 +02:00
|
|
|
* PARAMS
|
2019-06-20 09:12:29 +02:00
|
|
|
* lpszStr [O] Destination string
|
|
|
|
* lpszSrc [I] Source string
|
2002-08-20 01:57:27 +02:00
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* lpszStr.
|
2000-07-26 19:51:32 +02:00
|
|
|
*/
|
2019-06-20 09:12:29 +02:00
|
|
|
LPWSTR WINAPI StrCpyW(LPWSTR lpszStr, LPCWSTR lpszSrc)
|
2000-07-26 19:51:32 +02:00
|
|
|
{
|
2019-06-20 09:12:29 +02:00
|
|
|
TRACE("(%p,%s)\n", lpszStr, debugstr_w(lpszSrc));
|
2002-08-20 01:57:27 +02:00
|
|
|
|
2019-06-20 09:12:29 +02:00
|
|
|
if (lpszStr && lpszSrc)
|
2019-06-20 09:13:05 +02:00
|
|
|
lstrcpyW(lpszStr, lpszSrc);
|
2002-08-20 01:57:27 +02:00
|
|
|
return lpszStr;
|
2000-07-26 19:51:32 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/*************************************************************************
|
|
|
|
* StrRetToBufA [SHLWAPI.@]
|
2002-06-01 01:06:46 +02:00
|
|
|
*
|
2002-08-20 01:57:27 +02:00
|
|
|
* Convert a STRRET to a normal string.
|
2000-07-26 19:51:32 +02:00
|
|
|
*
|
2002-08-20 01:57:27 +02:00
|
|
|
* PARAMS
|
|
|
|
* lpStrRet [O] STRRET to convert
|
2004-02-10 03:22:17 +01:00
|
|
|
* pIdl [I] ITEMIDLIST for lpStrRet->uType == STRRET_OFFSET
|
2002-08-20 01:57:27 +02:00
|
|
|
* lpszDest [O] Destination for normal string
|
|
|
|
* dwLen [I] Length of lpszDest
|
2001-11-06 00:55:36 +01:00
|
|
|
*
|
2002-08-20 01:57:27 +02:00
|
|
|
* RETURNS
|
|
|
|
* Success: S_OK. lpszDest contains up to dwLen characters of the string.
|
|
|
|
* If lpStrRet is of type STRRET_WSTR, its memory is freed with
|
2003-03-18 19:35:48 +01:00
|
|
|
* CoTaskMemFree() and its type set to STRRET_CSTRA.
|
2002-08-20 01:57:27 +02:00
|
|
|
* Failure: E_FAIL, if any parameters are invalid.
|
2000-07-26 19:51:32 +02:00
|
|
|
*/
|
2004-01-23 21:57:26 +01:00
|
|
|
HRESULT WINAPI StrRetToBufA (LPSTRRET src, const ITEMIDLIST *pidl, LPSTR dest, UINT len)
|
2000-07-26 19:51:32 +02:00
|
|
|
{
|
2002-08-20 01:57:27 +02:00
|
|
|
/* NOTE:
|
|
|
|
* This routine is identical to that in dlls/shell32/shellstring.c.
|
|
|
|
* It was duplicated because not every version of Shlwapi.dll exports
|
|
|
|
* StrRetToBufA. If you change one routine, change them both.
|
|
|
|
*/
|
2012-09-11 12:13:19 +02:00
|
|
|
TRACE("dest=%p len=0x%x strret=%p pidl=%p\n", dest, len, src, pidl);
|
2000-07-26 19:51:32 +02:00
|
|
|
|
2002-08-20 01:57:27 +02:00
|
|
|
if (!src)
|
|
|
|
{
|
|
|
|
WARN("Invalid lpStrRet would crash under Win32!\n");
|
|
|
|
if (dest)
|
|
|
|
*dest = '\0';
|
|
|
|
return E_FAIL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!dest || !len)
|
|
|
|
return E_FAIL;
|
|
|
|
|
|
|
|
*dest = '\0';
|
|
|
|
|
2000-07-26 19:51:32 +02:00
|
|
|
switch (src->uType)
|
|
|
|
{
|
|
|
|
case STRRET_WSTR:
|
2002-08-20 01:57:27 +02:00
|
|
|
WideCharToMultiByte(CP_ACP, 0, src->u.pOleStr, -1, dest, len, NULL, NULL);
|
2002-07-02 04:06:19 +02:00
|
|
|
CoTaskMemFree(src->u.pOleStr);
|
2000-07-26 19:51:32 +02:00
|
|
|
break;
|
|
|
|
|
2002-07-02 04:06:19 +02:00
|
|
|
case STRRET_CSTR:
|
2009-01-22 09:52:44 +01:00
|
|
|
lstrcpynA(dest, src->u.cStr, len);
|
2000-07-26 19:51:32 +02:00
|
|
|
break;
|
|
|
|
|
2002-07-02 04:06:19 +02:00
|
|
|
case STRRET_OFFSET:
|
2020-09-28 21:28:07 +02:00
|
|
|
lstrcpynA(dest, ((LPCSTR)&pidl->mkid)+src->u.uOffset, len);
|
2000-07-26 19:51:32 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
FIXME("unknown type!\n");
|
2016-09-13 23:20:28 +02:00
|
|
|
return E_NOTIMPL;
|
2000-07-26 19:51:32 +02:00
|
|
|
}
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*************************************************************************
|
2002-08-20 01:57:27 +02:00
|
|
|
* StrRetToBufW [SHLWAPI.@]
|
2002-06-01 01:06:46 +02:00
|
|
|
*
|
2002-08-20 01:57:27 +02:00
|
|
|
* See StrRetToBufA.
|
2000-07-26 19:51:32 +02:00
|
|
|
*/
|
2004-01-23 21:57:26 +01:00
|
|
|
HRESULT WINAPI StrRetToBufW (LPSTRRET src, const ITEMIDLIST *pidl, LPWSTR dest, UINT len)
|
2000-07-26 19:51:32 +02:00
|
|
|
{
|
2017-02-23 15:42:41 +01:00
|
|
|
TRACE("dest=%p len=0x%x strret=%p pidl=%p\n", dest, len, src, pidl);
|
2000-07-26 19:51:32 +02:00
|
|
|
|
2017-02-23 15:42:41 +01:00
|
|
|
if (!dest || !len)
|
|
|
|
return E_FAIL;
|
2002-08-20 01:57:27 +02:00
|
|
|
|
2017-02-23 15:42:41 +01:00
|
|
|
if (!src)
|
|
|
|
{
|
|
|
|
WARN("Invalid lpStrRet would crash under Win32!\n");
|
2019-02-28 00:50:32 +01:00
|
|
|
*dest = '\0';
|
2017-02-23 15:42:41 +01:00
|
|
|
return E_FAIL;
|
|
|
|
}
|
2002-08-20 01:57:27 +02:00
|
|
|
|
2017-02-23 15:42:41 +01:00
|
|
|
*dest = '\0';
|
|
|
|
|
|
|
|
switch (src->uType) {
|
|
|
|
case STRRET_WSTR: {
|
|
|
|
size_t dst_len;
|
|
|
|
if (!src->u.pOleStr)
|
|
|
|
return E_FAIL;
|
2019-06-20 09:13:05 +02:00
|
|
|
dst_len = lstrlenW(src->u.pOleStr);
|
2017-02-23 15:42:41 +01:00
|
|
|
memcpy(dest, src->u.pOleStr, min(dst_len, len-1) * sizeof(WCHAR));
|
|
|
|
dest[min(dst_len, len-1)] = 0;
|
|
|
|
CoTaskMemFree(src->u.pOleStr);
|
|
|
|
if (len <= dst_len)
|
|
|
|
{
|
|
|
|
dest[0] = 0;
|
|
|
|
return E_NOT_SUFFICIENT_BUFFER;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2002-08-20 01:57:27 +02:00
|
|
|
|
2017-02-23 15:42:41 +01:00
|
|
|
case STRRET_CSTR:
|
|
|
|
if (!MultiByteToWideChar( CP_ACP, 0, src->u.cStr, -1, dest, len ))
|
|
|
|
dest[len-1] = 0;
|
|
|
|
break;
|
2000-07-26 19:51:32 +02:00
|
|
|
|
2017-02-23 15:42:41 +01:00
|
|
|
case STRRET_OFFSET:
|
|
|
|
if (pidl)
|
|
|
|
{
|
|
|
|
if (!MultiByteToWideChar( CP_ACP, 0, ((LPCSTR)&pidl->mkid)+src->u.uOffset, -1,
|
|
|
|
dest, len ))
|
|
|
|
dest[len-1] = 0;
|
|
|
|
}
|
|
|
|
break;
|
2000-07-26 19:51:32 +02:00
|
|
|
|
2017-02-23 15:42:41 +01:00
|
|
|
default:
|
|
|
|
FIXME("unknown type!\n");
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
2000-07-26 19:51:32 +02:00
|
|
|
|
2017-02-23 15:42:41 +01:00
|
|
|
return S_OK;
|
2000-07-26 19:51:32 +02:00
|
|
|
}
|
|
|
|
|
2002-08-07 01:50:27 +02:00
|
|
|
/*************************************************************************
|
|
|
|
* StrRetToStrA [SHLWAPI.@]
|
|
|
|
*
|
2003-07-22 05:13:22 +02:00
|
|
|
* Converts a STRRET to a normal string.
|
|
|
|
*
|
|
|
|
* PARAMS
|
|
|
|
* lpStrRet [O] STRRET to convert
|
2004-02-10 03:22:17 +01:00
|
|
|
* pidl [I] ITEMIDLIST for lpStrRet->uType == STRRET_OFFSET
|
2003-07-22 05:13:22 +02:00
|
|
|
* ppszName [O] Destination for converted string
|
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* Success: S_OK. ppszName contains the new string, allocated with CoTaskMemAlloc().
|
|
|
|
* Failure: E_FAIL, if any parameters are invalid.
|
2002-08-07 01:50:27 +02:00
|
|
|
*/
|
2003-07-22 05:13:22 +02:00
|
|
|
HRESULT WINAPI StrRetToStrA(LPSTRRET lpStrRet, const ITEMIDLIST *pidl, LPSTR *ppszName)
|
2002-08-07 01:50:27 +02:00
|
|
|
{
|
2003-07-22 05:13:22 +02:00
|
|
|
HRESULT hRet = E_FAIL;
|
2002-08-07 01:50:27 +02:00
|
|
|
|
2003-07-22 05:13:22 +02:00
|
|
|
switch (lpStrRet->uType)
|
|
|
|
{
|
|
|
|
case STRRET_WSTR:
|
|
|
|
hRet = _SHStrDupAW(lpStrRet->u.pOleStr, ppszName);
|
|
|
|
CoTaskMemFree(lpStrRet->u.pOleStr);
|
|
|
|
break;
|
2002-08-07 01:50:27 +02:00
|
|
|
|
2003-07-22 05:13:22 +02:00
|
|
|
case STRRET_CSTR:
|
|
|
|
hRet = _SHStrDupAA(lpStrRet->u.cStr, ppszName);
|
|
|
|
break;
|
2002-08-07 01:50:27 +02:00
|
|
|
|
2003-07-22 05:13:22 +02:00
|
|
|
case STRRET_OFFSET:
|
|
|
|
hRet = _SHStrDupAA(((LPCSTR)&pidl->mkid) + lpStrRet->u.uOffset, ppszName);
|
|
|
|
break;
|
2002-08-07 01:50:27 +02:00
|
|
|
|
2003-07-22 05:13:22 +02:00
|
|
|
default:
|
|
|
|
*ppszName = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return hRet;
|
2002-08-07 01:50:27 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/*************************************************************************
|
|
|
|
* StrRetToStrW [SHLWAPI.@]
|
|
|
|
*
|
2003-07-22 05:13:22 +02:00
|
|
|
* See StrRetToStrA.
|
2002-08-07 01:50:27 +02:00
|
|
|
*/
|
2003-07-22 05:13:22 +02:00
|
|
|
HRESULT WINAPI StrRetToStrW(LPSTRRET lpStrRet, const ITEMIDLIST *pidl, LPWSTR *ppszName)
|
2002-08-07 01:50:27 +02:00
|
|
|
{
|
2003-07-22 05:13:22 +02:00
|
|
|
HRESULT hRet = E_FAIL;
|
2002-08-07 01:50:27 +02:00
|
|
|
|
2003-07-22 05:13:22 +02:00
|
|
|
switch (lpStrRet->uType)
|
|
|
|
{
|
|
|
|
case STRRET_WSTR:
|
|
|
|
hRet = SHStrDupW(lpStrRet->u.pOleStr, ppszName);
|
|
|
|
CoTaskMemFree(lpStrRet->u.pOleStr);
|
|
|
|
break;
|
2002-08-07 01:50:27 +02:00
|
|
|
|
2003-07-22 05:13:22 +02:00
|
|
|
case STRRET_CSTR:
|
|
|
|
hRet = SHStrDupA(lpStrRet->u.cStr, ppszName);
|
|
|
|
break;
|
2002-08-07 01:50:27 +02:00
|
|
|
|
2003-07-22 05:13:22 +02:00
|
|
|
case STRRET_OFFSET:
|
|
|
|
hRet = SHStrDupA(((LPCSTR)&pidl->mkid) + lpStrRet->u.uOffset, ppszName);
|
|
|
|
break;
|
2002-08-07 01:50:27 +02:00
|
|
|
|
2003-07-22 05:13:22 +02:00
|
|
|
default:
|
|
|
|
*ppszName = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return hRet;
|
2002-08-07 01:50:27 +02:00
|
|
|
}
|
|
|
|
|
2021-08-30 17:17:35 +02:00
|
|
|
/* Makes a Unicode copy of an ANSI string using SysAllocString() */
|
2004-02-10 03:22:17 +01:00
|
|
|
static HRESULT _SHStrDupAToBSTR(LPCSTR src, BSTR *pBstrOut)
|
|
|
|
{
|
|
|
|
*pBstrOut = NULL;
|
|
|
|
|
|
|
|
if (src)
|
|
|
|
{
|
|
|
|
INT len = MultiByteToWideChar(CP_ACP, 0, src, -1, NULL, 0);
|
|
|
|
WCHAR* szTemp = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
|
|
|
|
|
|
|
|
if (szTemp)
|
|
|
|
{
|
|
|
|
MultiByteToWideChar(CP_ACP, 0, src, -1, szTemp, len);
|
|
|
|
*pBstrOut = SysAllocString(szTemp);
|
|
|
|
HeapFree(GetProcessHeap(), 0, szTemp);
|
|
|
|
|
|
|
|
if (*pBstrOut)
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return E_OUTOFMEMORY;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*************************************************************************
|
|
|
|
* StrRetToBSTR [SHLWAPI.@]
|
|
|
|
*
|
|
|
|
* Converts a STRRET to a BSTR.
|
|
|
|
*
|
|
|
|
* PARAMS
|
|
|
|
* lpStrRet [O] STRRET to convert
|
|
|
|
* pidl [I] ITEMIDLIST for lpStrRet->uType = STRRET_OFFSET
|
|
|
|
* pBstrOut [O] Destination for converted BSTR
|
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* Success: S_OK. pBstrOut contains the new string.
|
|
|
|
* Failure: E_FAIL, if any parameters are invalid.
|
|
|
|
*/
|
|
|
|
HRESULT WINAPI StrRetToBSTR(STRRET *lpStrRet, LPCITEMIDLIST pidl, BSTR* pBstrOut)
|
|
|
|
{
|
|
|
|
HRESULT hRet = E_FAIL;
|
|
|
|
|
|
|
|
switch (lpStrRet->uType)
|
|
|
|
{
|
|
|
|
case STRRET_WSTR:
|
|
|
|
*pBstrOut = SysAllocString(lpStrRet->u.pOleStr);
|
|
|
|
if (*pBstrOut)
|
|
|
|
hRet = S_OK;
|
|
|
|
CoTaskMemFree(lpStrRet->u.pOleStr);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case STRRET_CSTR:
|
|
|
|
hRet = _SHStrDupAToBSTR(lpStrRet->u.cStr, pBstrOut);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case STRRET_OFFSET:
|
|
|
|
hRet = _SHStrDupAToBSTR(((LPCSTR)&pidl->mkid) + lpStrRet->u.uOffset, pBstrOut);
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
*pBstrOut = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return hRet;
|
|
|
|
}
|
|
|
|
|
2001-04-25 21:51:56 +02:00
|
|
|
/*************************************************************************
|
2002-08-20 01:57:27 +02:00
|
|
|
* StrFormatKBSizeA [SHLWAPI.@]
|
|
|
|
*
|
|
|
|
* Create a formatted string containing a byte count in Kilobytes.
|
|
|
|
*
|
|
|
|
* PARAMS
|
|
|
|
* llBytes [I] Byte size to format
|
|
|
|
* lpszDest [I] Destination for formatted string
|
|
|
|
* cchMax [I] Size of lpszDest
|
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* lpszDest.
|
|
|
|
*/
|
|
|
|
LPSTR WINAPI StrFormatKBSizeA(LONGLONG llBytes, LPSTR lpszDest, UINT cchMax)
|
|
|
|
{
|
2006-08-21 23:40:36 +02:00
|
|
|
WCHAR wszBuf[256];
|
|
|
|
|
|
|
|
if (!StrFormatKBSizeW(llBytes, wszBuf, 256))
|
|
|
|
return NULL;
|
|
|
|
if (!WideCharToMultiByte(CP_ACP, 0, wszBuf, -1, lpszDest, cchMax, NULL, NULL))
|
|
|
|
return NULL;
|
2002-08-20 01:57:27 +02:00
|
|
|
return lpszDest;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*************************************************************************
|
|
|
|
* StrFormatKBSizeW [SHLWAPI.@]
|
|
|
|
*
|
|
|
|
* See StrFormatKBSizeA.
|
|
|
|
*/
|
|
|
|
LPWSTR WINAPI StrFormatKBSizeW(LONGLONG llBytes, LPWSTR lpszDest, UINT cchMax)
|
|
|
|
{
|
2006-08-21 23:40:36 +02:00
|
|
|
static const WCHAR kb[] = {' ','K','B',0};
|
|
|
|
LONGLONG llKB = (llBytes + 1023) >> 10;
|
|
|
|
int len;
|
2002-08-20 01:57:27 +02:00
|
|
|
|
2006-08-17 18:57:42 +02:00
|
|
|
TRACE("(0x%s,%p,%d)\n", wine_dbgstr_longlong(llBytes), lpszDest, cchMax);
|
2002-08-20 01:57:27 +02:00
|
|
|
|
2006-08-21 23:40:36 +02:00
|
|
|
if (!FormatInt(llKB, lpszDest, cchMax))
|
|
|
|
return NULL;
|
2002-08-20 01:57:27 +02:00
|
|
|
|
2006-08-21 23:40:36 +02:00
|
|
|
len = lstrlenW(lpszDest);
|
|
|
|
if (cchMax - len < 4)
|
|
|
|
return NULL;
|
|
|
|
lstrcatW(lpszDest, kb);
|
2002-08-20 01:57:27 +02:00
|
|
|
return lpszDest;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*************************************************************************
|
|
|
|
* StrNCatA [SHLWAPI.@]
|
|
|
|
*
|
|
|
|
* Concatenate two strings together.
|
|
|
|
*
|
|
|
|
* PARAMS
|
|
|
|
* lpszStr [O] String to concatenate to
|
|
|
|
* lpszCat [I] String to add to lpszCat
|
|
|
|
* cchMax [I] Maximum number of characters to concatenate
|
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* lpszStr.
|
|
|
|
*
|
|
|
|
* NOTES
|
2003-07-22 05:13:22 +02:00
|
|
|
* cchMax determines the number of characters that are appended to lpszStr,
|
2002-08-20 01:57:27 +02:00
|
|
|
* not the total length of the string.
|
|
|
|
*/
|
|
|
|
LPSTR WINAPI StrNCatA(LPSTR lpszStr, LPCSTR lpszCat, INT cchMax)
|
|
|
|
{
|
|
|
|
LPSTR lpszRet = lpszStr;
|
|
|
|
|
|
|
|
TRACE("(%s,%s,%i)\n", debugstr_a(lpszStr), debugstr_a(lpszCat), cchMax);
|
|
|
|
|
|
|
|
if (!lpszStr)
|
|
|
|
{
|
|
|
|
WARN("Invalid lpszStr would crash under Win32!\n");
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
StrCpyNA(lpszStr + strlen(lpszStr), lpszCat, cchMax);
|
|
|
|
return lpszRet;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*************************************************************************
|
|
|
|
* StrNCatW [SHLWAPI.@]
|
|
|
|
*
|
|
|
|
* See StrNCatA.
|
2001-04-25 21:51:56 +02:00
|
|
|
*/
|
2002-08-20 01:57:27 +02:00
|
|
|
LPWSTR WINAPI StrNCatW(LPWSTR lpszStr, LPCWSTR lpszCat, INT cchMax)
|
2001-04-25 21:51:56 +02:00
|
|
|
{
|
2002-08-20 01:57:27 +02:00
|
|
|
LPWSTR lpszRet = lpszStr;
|
|
|
|
|
|
|
|
TRACE("(%s,%s,%i)\n", debugstr_w(lpszStr), debugstr_w(lpszCat), cchMax);
|
|
|
|
|
|
|
|
if (!lpszStr)
|
|
|
|
{
|
|
|
|
WARN("Invalid lpszStr would crash under Win32\n");
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2019-06-20 09:13:05 +02:00
|
|
|
StrCpyNW(lpszStr + lstrlenW(lpszStr), lpszCat, cchMax);
|
2002-08-20 01:57:27 +02:00
|
|
|
return lpszRet;
|
2001-04-25 21:51:56 +02:00
|
|
|
}
|
|
|
|
|
2002-08-07 01:50:27 +02:00
|
|
|
/*************************************************************************
|
2003-07-22 05:13:22 +02:00
|
|
|
* _SHStrDupAA [INTERNAL]
|
2002-08-07 01:50:27 +02:00
|
|
|
*
|
2021-08-30 17:17:19 +02:00
|
|
|
* Duplicates a ANSI string to ANSI. The destination buffer is allocated.
|
2002-08-07 01:50:27 +02:00
|
|
|
*/
|
2007-06-25 14:01:28 +02:00
|
|
|
static HRESULT _SHStrDupAA(LPCSTR src, LPSTR * dest)
|
2002-08-07 01:50:27 +02:00
|
|
|
{
|
|
|
|
HRESULT hr;
|
|
|
|
int len = 0;
|
|
|
|
|
|
|
|
if (src) {
|
2003-03-18 19:35:48 +01:00
|
|
|
len = lstrlenA(src) + 1;
|
2002-08-07 01:50:27 +02:00
|
|
|
*dest = CoTaskMemAlloc(len);
|
|
|
|
} else {
|
|
|
|
*dest = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (*dest) {
|
|
|
|
lstrcpynA(*dest,src, len);
|
|
|
|
hr = S_OK;
|
|
|
|
} else {
|
|
|
|
hr = E_OUTOFMEMORY;
|
|
|
|
}
|
|
|
|
|
|
|
|
TRACE("%s->(%p)\n", debugstr_a(src), *dest);
|
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
2002-07-20 22:04:44 +02:00
|
|
|
/*************************************************************************
|
2003-10-01 05:20:21 +02:00
|
|
|
* SHStrDupA [SHLWAPI.@]
|
2002-08-20 01:57:27 +02:00
|
|
|
*
|
2003-03-18 19:35:48 +01:00
|
|
|
* Return a Unicode copy of a string, in memory allocated by CoTaskMemAlloc().
|
2002-07-20 22:04:44 +02:00
|
|
|
*
|
2002-08-20 01:57:27 +02:00
|
|
|
* PARAMS
|
|
|
|
* lpszStr [I] String to copy
|
|
|
|
* lppszDest [O] Destination for the new string copy
|
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* Success: S_OK. lppszDest contains the new string in Unicode format.
|
|
|
|
* Failure: E_OUTOFMEMORY, If any arguments are invalid or memory allocation
|
|
|
|
* fails.
|
2002-07-20 22:04:44 +02:00
|
|
|
*/
|
2003-07-22 05:13:22 +02:00
|
|
|
HRESULT WINAPI SHStrDupA(LPCSTR lpszStr, LPWSTR * lppszDest)
|
2002-07-20 22:04:44 +02:00
|
|
|
{
|
2003-07-22 05:13:22 +02:00
|
|
|
HRESULT hRet;
|
|
|
|
int len = 0;
|
2002-07-20 22:04:44 +02:00
|
|
|
|
2003-07-22 05:13:22 +02:00
|
|
|
if (lpszStr)
|
|
|
|
{
|
2012-09-24 13:04:26 +02:00
|
|
|
len = MultiByteToWideChar(CP_ACP, 0, lpszStr, -1, NULL, 0) * sizeof(WCHAR);
|
2003-07-22 05:13:22 +02:00
|
|
|
*lppszDest = CoTaskMemAlloc(len);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
*lppszDest = NULL;
|
2002-07-20 22:04:44 +02:00
|
|
|
|
2003-07-22 05:13:22 +02:00
|
|
|
if (*lppszDest)
|
|
|
|
{
|
2012-09-24 13:04:26 +02:00
|
|
|
MultiByteToWideChar(CP_ACP, 0, lpszStr, -1, *lppszDest, len/sizeof(WCHAR));
|
2003-07-22 05:13:22 +02:00
|
|
|
hRet = S_OK;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
hRet = E_OUTOFMEMORY;
|
2002-07-20 22:04:44 +02:00
|
|
|
|
2003-07-22 05:13:22 +02:00
|
|
|
TRACE("%s->(%p)\n", debugstr_a(lpszStr), *lppszDest);
|
|
|
|
return hRet;
|
2002-07-20 22:04:44 +02:00
|
|
|
}
|
|
|
|
|
2002-08-07 01:50:27 +02:00
|
|
|
/*************************************************************************
|
|
|
|
* _SHStrDupAW [INTERNAL]
|
|
|
|
*
|
2021-08-30 17:17:19 +02:00
|
|
|
* Duplicates a UNICODE to a ANSI string. The destination buffer is allocated.
|
2002-08-07 01:50:27 +02:00
|
|
|
*/
|
2007-06-25 14:01:28 +02:00
|
|
|
static HRESULT _SHStrDupAW(LPCWSTR src, LPSTR * dest)
|
2002-08-07 01:50:27 +02:00
|
|
|
{
|
|
|
|
HRESULT hr;
|
|
|
|
int len = 0;
|
|
|
|
|
|
|
|
if (src) {
|
|
|
|
len = WideCharToMultiByte(CP_ACP, 0, src, -1, NULL, 0, NULL, NULL);
|
|
|
|
*dest = CoTaskMemAlloc(len);
|
|
|
|
} else {
|
|
|
|
*dest = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (*dest) {
|
|
|
|
WideCharToMultiByte(CP_ACP, 0, src, -1, *dest, len, NULL, NULL);
|
|
|
|
hr = S_OK;
|
|
|
|
} else {
|
|
|
|
hr = E_OUTOFMEMORY;
|
|
|
|
}
|
|
|
|
|
|
|
|
TRACE("%s->(%p)\n", debugstr_w(src), *dest);
|
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
2002-07-20 22:04:44 +02:00
|
|
|
/*************************************************************************
|
2003-10-01 05:20:21 +02:00
|
|
|
* SHStrDupW [SHLWAPI.@]
|
2002-07-20 22:04:44 +02:00
|
|
|
*
|
2002-08-20 01:57:27 +02:00
|
|
|
* See SHStrDupA.
|
2002-07-20 22:04:44 +02:00
|
|
|
*/
|
|
|
|
HRESULT WINAPI SHStrDupW(LPCWSTR src, LPWSTR * dest)
|
|
|
|
{
|
|
|
|
HRESULT hr;
|
|
|
|
int len = 0;
|
|
|
|
|
|
|
|
if (src) {
|
|
|
|
len = (lstrlenW(src) + 1) * sizeof(WCHAR);
|
|
|
|
*dest = CoTaskMemAlloc(len);
|
|
|
|
} else {
|
|
|
|
*dest = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (*dest) {
|
|
|
|
memcpy(*dest, src, len);
|
|
|
|
hr = S_OK;
|
|
|
|
} else {
|
|
|
|
hr = E_OUTOFMEMORY;
|
|
|
|
}
|
|
|
|
|
|
|
|
TRACE("%s->(%p)\n", debugstr_w(src), *dest);
|
|
|
|
return hr;
|
|
|
|
}
|
2002-08-20 01:57:27 +02:00
|
|
|
|
|
|
|
/*************************************************************************
|
|
|
|
* SHLWAPI_WriteReverseNum
|
|
|
|
*
|
|
|
|
* Internal helper for SHLWAPI_WriteTimeClass.
|
|
|
|
*/
|
2007-03-23 16:08:37 +01:00
|
|
|
static inline LPWSTR SHLWAPI_WriteReverseNum(LPWSTR lpszOut, DWORD dwNum)
|
2002-08-20 01:57:27 +02:00
|
|
|
{
|
|
|
|
*lpszOut-- = '\0';
|
|
|
|
|
|
|
|
/* Write a decimal number to a string, backwards */
|
|
|
|
do
|
|
|
|
{
|
|
|
|
DWORD dwNextDigit = dwNum % 10;
|
|
|
|
*lpszOut-- = '0' + dwNextDigit;
|
|
|
|
dwNum = (dwNum - dwNextDigit) / 10;
|
|
|
|
} while (dwNum > 0);
|
|
|
|
|
|
|
|
return lpszOut;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*************************************************************************
|
|
|
|
* SHLWAPI_FormatSignificant
|
|
|
|
*
|
|
|
|
* Internal helper for SHLWAPI_WriteTimeClass.
|
|
|
|
*/
|
2007-03-23 16:08:37 +01:00
|
|
|
static inline int SHLWAPI_FormatSignificant(LPWSTR lpszNum, int dwDigits)
|
2002-08-20 01:57:27 +02:00
|
|
|
{
|
|
|
|
/* Zero non significant digits, return remaining significant digits */
|
|
|
|
while (*lpszNum)
|
|
|
|
{
|
|
|
|
lpszNum++;
|
|
|
|
if (--dwDigits == 0)
|
|
|
|
{
|
|
|
|
while (*lpszNum)
|
|
|
|
*lpszNum++ = '0';
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return dwDigits;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*************************************************************************
|
|
|
|
* SHLWAPI_WriteTimeClass
|
|
|
|
*
|
|
|
|
* Internal helper for StrFromTimeIntervalW.
|
|
|
|
*/
|
2007-06-25 14:01:28 +02:00
|
|
|
static int SHLWAPI_WriteTimeClass(LPWSTR lpszOut, DWORD dwValue,
|
|
|
|
UINT uClassStringId, int iDigits)
|
2002-08-20 01:57:27 +02:00
|
|
|
{
|
|
|
|
WCHAR szBuff[64], *szOut = szBuff + 32;
|
|
|
|
|
|
|
|
szOut = SHLWAPI_WriteReverseNum(szOut, dwValue);
|
|
|
|
iDigits = SHLWAPI_FormatSignificant(szOut + 1, iDigits);
|
|
|
|
*szOut = ' ';
|
2006-08-23 14:13:32 +02:00
|
|
|
LoadStringW(shlwapi_hInstance, uClassStringId, szBuff + 32, 32);
|
2019-06-20 09:13:05 +02:00
|
|
|
lstrcatW(lpszOut, szOut);
|
2002-08-20 01:57:27 +02:00
|
|
|
return iDigits;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*************************************************************************
|
|
|
|
* StrFromTimeIntervalA [SHLWAPI.@]
|
|
|
|
*
|
|
|
|
* Format a millisecond time interval into a string
|
|
|
|
*
|
|
|
|
* PARAMS
|
|
|
|
* lpszStr [O] Output buffer for formatted time interval
|
|
|
|
* cchMax [I] Size of lpszStr
|
|
|
|
* dwMS [I] Number of milliseconds
|
|
|
|
* iDigits [I] Number of digits to print
|
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* The length of the formatted string, or 0 if any parameter is invalid.
|
|
|
|
*
|
|
|
|
* NOTES
|
|
|
|
* This implementation mimics the Win32 behaviour of always writing a leading
|
|
|
|
* space before the time interval begins.
|
2003-03-18 19:35:48 +01:00
|
|
|
*
|
2002-08-20 01:57:27 +02:00
|
|
|
* iDigits is used to provide approximate times if accuracy is not important.
|
|
|
|
* This number of digits will be written of the first non-zero time class
|
|
|
|
* (hours/minutes/seconds). If this does not complete the time classification,
|
|
|
|
* the remaining digits are changed to zeros (i.e. The time is _not_ rounded).
|
|
|
|
* If there are digits remaining following the writing of a time class, the
|
|
|
|
* next time class will be written.
|
2003-03-18 19:35:48 +01:00
|
|
|
*
|
2002-08-20 01:57:27 +02:00
|
|
|
* For example, given dwMS represents 138 hours,43 minutes and 15 seconds, the
|
|
|
|
* following will result from the given values of iDigits:
|
|
|
|
*
|
2003-03-18 19:35:48 +01:00
|
|
|
*| iDigits 1 2 3 4 5 ...
|
|
|
|
*| lpszStr "100 hr" "130 hr" "138 hr" "138 hr 40 min" "138 hr 43 min" ...
|
2002-08-20 01:57:27 +02:00
|
|
|
*/
|
|
|
|
INT WINAPI StrFromTimeIntervalA(LPSTR lpszStr, UINT cchMax, DWORD dwMS,
|
|
|
|
int iDigits)
|
|
|
|
{
|
|
|
|
INT iRet = 0;
|
|
|
|
|
2022-02-18 09:16:21 +01:00
|
|
|
TRACE("(%p,%d,%ld,%d)\n", lpszStr, cchMax, dwMS, iDigits);
|
2002-08-20 01:57:27 +02:00
|
|
|
|
|
|
|
if (lpszStr && cchMax)
|
|
|
|
{
|
|
|
|
WCHAR szBuff[128];
|
2018-09-15 00:10:31 +02:00
|
|
|
StrFromTimeIntervalW(szBuff, ARRAY_SIZE(szBuff), dwMS, iDigits);
|
2002-08-20 01:57:27 +02:00
|
|
|
WideCharToMultiByte(CP_ACP,0,szBuff,-1,lpszStr,cchMax,0,0);
|
|
|
|
}
|
|
|
|
return iRet;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*************************************************************************
|
|
|
|
* StrFromTimeIntervalW [SHLWAPI.@]
|
|
|
|
*
|
|
|
|
* See StrFromTimeIntervalA.
|
|
|
|
*/
|
|
|
|
INT WINAPI StrFromTimeIntervalW(LPWSTR lpszStr, UINT cchMax, DWORD dwMS,
|
|
|
|
int iDigits)
|
|
|
|
{
|
|
|
|
INT iRet = 0;
|
|
|
|
|
2022-02-18 09:16:21 +01:00
|
|
|
TRACE("(%p,%d,%ld,%d)\n", lpszStr, cchMax, dwMS, iDigits);
|
2002-08-20 01:57:27 +02:00
|
|
|
|
|
|
|
if (lpszStr && cchMax)
|
|
|
|
{
|
|
|
|
WCHAR szCopy[128];
|
|
|
|
DWORD dwHours, dwMinutes;
|
|
|
|
|
|
|
|
if (!iDigits || cchMax == 1)
|
|
|
|
{
|
|
|
|
*lpszStr = '\0';
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Calculate the time classes */
|
|
|
|
dwMS = (dwMS + 500) / 1000;
|
|
|
|
dwHours = dwMS / 3600;
|
|
|
|
dwMS -= dwHours * 3600;
|
|
|
|
dwMinutes = dwMS / 60;
|
|
|
|
dwMS -= dwMinutes * 60;
|
|
|
|
|
|
|
|
szCopy[0] = '\0';
|
|
|
|
|
|
|
|
if (dwHours)
|
2006-08-23 14:13:32 +02:00
|
|
|
iDigits = SHLWAPI_WriteTimeClass(szCopy, dwHours, IDS_TIME_INTERVAL_HOURS, iDigits);
|
2002-08-20 01:57:27 +02:00
|
|
|
|
|
|
|
if (dwMinutes && iDigits)
|
2006-08-23 14:13:32 +02:00
|
|
|
iDigits = SHLWAPI_WriteTimeClass(szCopy, dwMinutes, IDS_TIME_INTERVAL_MINUTES, iDigits);
|
2002-08-20 01:57:27 +02:00
|
|
|
|
|
|
|
if (iDigits) /* Always write seconds if we have significant digits */
|
2006-08-23 14:13:32 +02:00
|
|
|
SHLWAPI_WriteTimeClass(szCopy, dwMS, IDS_TIME_INTERVAL_SECONDS, iDigits);
|
2002-08-20 01:57:27 +02:00
|
|
|
|
2005-03-28 16:17:51 +02:00
|
|
|
lstrcpynW(lpszStr, szCopy, cchMax);
|
2019-06-20 09:13:05 +02:00
|
|
|
iRet = lstrlenW(lpszStr);
|
2002-08-20 01:57:27 +02:00
|
|
|
}
|
|
|
|
return iRet;
|
|
|
|
}
|
|
|
|
|
2002-09-20 21:41:08 +02:00
|
|
|
/* Structure for formatting byte strings */
|
|
|
|
typedef struct tagSHLWAPI_BYTEFORMATS
|
|
|
|
{
|
|
|
|
LONGLONG dLimit;
|
|
|
|
double dDivisor;
|
|
|
|
double dNormaliser;
|
2006-08-22 16:52:52 +02:00
|
|
|
int nDecimals;
|
2005-01-03 21:09:22 +01:00
|
|
|
WCHAR wPrefix;
|
2002-09-20 21:41:08 +02:00
|
|
|
} SHLWAPI_BYTEFORMATS;
|
|
|
|
|
|
|
|
/*************************************************************************
|
2005-01-03 21:09:22 +01:00
|
|
|
* StrFormatByteSizeW [SHLWAPI.@]
|
2002-09-20 21:41:08 +02:00
|
|
|
*
|
|
|
|
* Create a string containing an abbreviated byte count of up to 2^63-1.
|
|
|
|
*
|
|
|
|
* PARAMS
|
|
|
|
* llBytes [I] Byte size to format
|
|
|
|
* lpszDest [I] Destination for formatted string
|
|
|
|
* cchMax [I] Size of lpszDest
|
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* lpszDest.
|
|
|
|
*
|
|
|
|
* NOTES
|
2003-03-18 19:35:48 +01:00
|
|
|
* There is no StrFormatByteSize64W function, it is called StrFormatByteSizeW().
|
2002-09-20 21:41:08 +02:00
|
|
|
*/
|
2005-01-03 21:09:22 +01:00
|
|
|
LPWSTR WINAPI StrFormatByteSizeW(LONGLONG llBytes, LPWSTR lpszDest, UINT cchMax)
|
2002-09-20 21:41:08 +02:00
|
|
|
{
|
2003-08-07 00:09:11 +02:00
|
|
|
#define KB ((ULONGLONG)1024)
|
|
|
|
#define MB (KB*KB)
|
|
|
|
#define GB (KB*KB*KB)
|
|
|
|
#define TB (KB*KB*KB*KB)
|
|
|
|
#define PB (KB*KB*KB*KB*KB)
|
|
|
|
|
2002-09-20 21:41:08 +02:00
|
|
|
static const SHLWAPI_BYTEFORMATS bfFormats[] =
|
|
|
|
{
|
2006-08-22 16:52:52 +02:00
|
|
|
{ 10*KB, 10.24, 100.0, 2, 'K' }, /* 10 KB */
|
|
|
|
{ 100*KB, 102.4, 10.0, 1, 'K' }, /* 100 KB */
|
|
|
|
{ 1000*KB, 1024.0, 1.0, 0, 'K' }, /* 1000 KB */
|
|
|
|
{ 10*MB, 10485.76, 100.0, 2, 'M' }, /* 10 MB */
|
|
|
|
{ 100*MB, 104857.6, 10.0, 1, 'M' }, /* 100 MB */
|
|
|
|
{ 1000*MB, 1048576.0, 1.0, 0, 'M' }, /* 1000 MB */
|
|
|
|
{ 10*GB, 10737418.24, 100.0, 2, 'G' }, /* 10 GB */
|
|
|
|
{ 100*GB, 107374182.4, 10.0, 1, 'G' }, /* 100 GB */
|
|
|
|
{ 1000*GB, 1073741824.0, 1.0, 0, 'G' }, /* 1000 GB */
|
|
|
|
{ 10*TB, 10485.76, 100.0, 2, 'T' }, /* 10 TB */
|
|
|
|
{ 100*TB, 104857.6, 10.0, 1, 'T' }, /* 100 TB */
|
|
|
|
{ 1000*TB, 1048576.0, 1.0, 0, 'T' }, /* 1000 TB */
|
|
|
|
{ 10*PB, 10737418.24, 100.00, 2, 'P' }, /* 10 PB */
|
|
|
|
{ 100*PB, 107374182.4, 10.00, 1, 'P' }, /* 100 PB */
|
|
|
|
{ 1000*PB, 1073741824.0, 1.00, 0, 'P' }, /* 1000 PB */
|
|
|
|
{ 0, 10995116277.76, 100.00, 2, 'E' } /* EB's, catch all */
|
2002-09-20 21:41:08 +02:00
|
|
|
};
|
2005-01-03 21:09:22 +01:00
|
|
|
WCHAR wszAdd[] = {' ','?','B',0};
|
2002-09-20 21:41:08 +02:00
|
|
|
double dBytes;
|
|
|
|
UINT i = 0;
|
|
|
|
|
2006-08-17 18:57:42 +02:00
|
|
|
TRACE("(0x%s,%p,%d)\n", wine_dbgstr_longlong(llBytes), lpszDest, cchMax);
|
2002-09-20 21:41:08 +02:00
|
|
|
|
|
|
|
if (!lpszDest || !cchMax)
|
|
|
|
return lpszDest;
|
|
|
|
|
|
|
|
if (llBytes < 1024) /* 1K */
|
|
|
|
{
|
2006-08-17 22:44:29 +02:00
|
|
|
WCHAR wszBytesFormat[64];
|
|
|
|
LoadStringW(shlwapi_hInstance, IDS_BYTES_FORMAT, wszBytesFormat, 64);
|
2019-06-20 09:13:05 +02:00
|
|
|
swprintf(lpszDest, cchMax, wszBytesFormat, (int)llBytes);
|
2002-09-20 21:41:08 +02:00
|
|
|
return lpszDest;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Note that if this loop completes without finding a match, i will be
|
|
|
|
* pointing at the last entry, which is a catch all for > 1000 PB
|
|
|
|
*/
|
2018-09-15 00:10:31 +02:00
|
|
|
while (i < ARRAY_SIZE(bfFormats) - 1)
|
2002-09-20 21:41:08 +02:00
|
|
|
{
|
|
|
|
if (llBytes < bfFormats[i].dLimit)
|
|
|
|
break;
|
|
|
|
i++;
|
|
|
|
}
|
|
|
|
/* Above 1 TB we encounter problems with FP accuracy. So for amounts above
|
|
|
|
* this number we integer shift down by 1 MB first. The table above has
|
|
|
|
* the divisors scaled down from the '< 10 TB' entry onwards, to account
|
|
|
|
* for this. We also add a small fudge factor to get the correct result for
|
|
|
|
* counts that lie exactly on a 1024 byte boundary.
|
|
|
|
*/
|
|
|
|
if (i > 8)
|
2011-09-27 00:14:10 +02:00
|
|
|
dBytes = (double)(llBytes >> 20) + 0.001; /* Scale down by 1 MB */
|
2002-09-20 21:41:08 +02:00
|
|
|
else
|
|
|
|
dBytes = (double)llBytes + 0.00001;
|
|
|
|
|
|
|
|
dBytes = floor(dBytes / bfFormats[i].dDivisor) / bfFormats[i].dNormaliser;
|
|
|
|
|
2006-08-22 16:52:52 +02:00
|
|
|
if (!FormatDouble(dBytes, bfFormats[i].nDecimals, lpszDest, cchMax))
|
|
|
|
return NULL;
|
2005-01-03 21:09:22 +01:00
|
|
|
wszAdd[1] = bfFormats[i].wPrefix;
|
2006-08-22 16:52:52 +02:00
|
|
|
StrCatBuffW(lpszDest, wszAdd, cchMax);
|
2002-09-20 21:41:08 +02:00
|
|
|
return lpszDest;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*************************************************************************
|
2005-01-03 21:09:22 +01:00
|
|
|
* StrFormatByteSize64A [SHLWAPI.@]
|
2002-09-20 21:41:08 +02:00
|
|
|
*
|
2005-01-03 21:09:22 +01:00
|
|
|
* See StrFormatByteSizeW.
|
2002-09-20 21:41:08 +02:00
|
|
|
*/
|
2005-01-03 21:09:22 +01:00
|
|
|
LPSTR WINAPI StrFormatByteSize64A(LONGLONG llBytes, LPSTR lpszDest, UINT cchMax)
|
2002-09-20 21:41:08 +02:00
|
|
|
{
|
2005-01-03 21:09:22 +01:00
|
|
|
WCHAR wszBuff[32];
|
2002-09-20 21:41:08 +02:00
|
|
|
|
2018-09-15 00:10:31 +02:00
|
|
|
StrFormatByteSizeW(llBytes, wszBuff, ARRAY_SIZE(wszBuff));
|
2002-09-20 21:41:08 +02:00
|
|
|
|
|
|
|
if (lpszDest)
|
2005-01-03 21:09:22 +01:00
|
|
|
WideCharToMultiByte(CP_ACP, 0, wszBuff, -1, lpszDest, cchMax, 0, 0);
|
2002-09-20 21:41:08 +02:00
|
|
|
return lpszDest;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*************************************************************************
|
|
|
|
* StrFormatByteSizeA [SHLWAPI.@]
|
|
|
|
*
|
|
|
|
* Create a string containing an abbreviated byte count of up to 2^31-1.
|
|
|
|
*
|
|
|
|
* PARAMS
|
|
|
|
* dwBytes [I] Byte size to format
|
|
|
|
* lpszDest [I] Destination for formatted string
|
|
|
|
* cchMax [I] Size of lpszDest
|
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* lpszDest.
|
|
|
|
*
|
|
|
|
* NOTES
|
2021-08-30 17:17:19 +02:00
|
|
|
* The ANSI and Unicode versions of this function accept a different
|
2003-03-18 19:35:48 +01:00
|
|
|
* integer type for dwBytes. See StrFormatByteSize64A().
|
2002-09-20 21:41:08 +02:00
|
|
|
*/
|
|
|
|
LPSTR WINAPI StrFormatByteSizeA(DWORD dwBytes, LPSTR lpszDest, UINT cchMax)
|
|
|
|
{
|
2022-02-18 09:16:21 +01:00
|
|
|
TRACE("(%ld,%p,%d)\n", dwBytes, lpszDest, cchMax);
|
2002-09-20 21:41:08 +02:00
|
|
|
|
|
|
|
return StrFormatByteSize64A(dwBytes, lpszDest, cchMax);
|
|
|
|
}
|
2003-07-22 05:13:22 +02:00
|
|
|
|
|
|
|
/*************************************************************************
|
2003-09-11 04:56:15 +02:00
|
|
|
* @ [SHLWAPI.203]
|
2003-07-22 05:13:22 +02:00
|
|
|
*
|
|
|
|
* Remove a single non-trailing ampersand ('&') from a string.
|
|
|
|
*
|
|
|
|
* PARAMS
|
|
|
|
* lpszStr [I/O] String to remove ampersand from.
|
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* The character after the first ampersand in lpszStr, or the first character
|
|
|
|
* in lpszStr if there is no ampersand in the string.
|
|
|
|
*/
|
2003-09-11 04:56:15 +02:00
|
|
|
char WINAPI SHStripMneumonicA(LPCSTR lpszStr)
|
2003-07-22 05:13:22 +02:00
|
|
|
{
|
|
|
|
LPSTR lpszIter, lpszTmp;
|
|
|
|
char ch;
|
|
|
|
|
|
|
|
TRACE("(%s)\n", debugstr_a(lpszStr));
|
|
|
|
|
|
|
|
ch = *lpszStr;
|
|
|
|
|
|
|
|
if ((lpszIter = StrChrA(lpszStr, '&')))
|
|
|
|
{
|
|
|
|
lpszTmp = CharNextA(lpszIter);
|
2011-06-15 10:07:55 +02:00
|
|
|
if (*lpszTmp)
|
2003-07-22 05:13:22 +02:00
|
|
|
{
|
|
|
|
if (*lpszTmp != '&')
|
|
|
|
ch = *lpszTmp;
|
|
|
|
|
2011-06-15 10:07:55 +02:00
|
|
|
memmove( lpszIter, lpszTmp, strlen(lpszTmp) + 1 );
|
2003-07-22 05:13:22 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return ch;
|
|
|
|
}
|
2004-02-17 23:48:56 +01:00
|
|
|
|
|
|
|
/*************************************************************************
|
2004-03-18 03:11:23 +01:00
|
|
|
* @ [SHLWAPI.225]
|
|
|
|
*
|
|
|
|
* Unicode version of SHStripMneumonicA.
|
|
|
|
*/
|
|
|
|
WCHAR WINAPI SHStripMneumonicW(LPCWSTR lpszStr)
|
|
|
|
{
|
|
|
|
LPWSTR lpszIter, lpszTmp;
|
|
|
|
WCHAR ch;
|
|
|
|
|
|
|
|
TRACE("(%s)\n", debugstr_w(lpszStr));
|
|
|
|
|
|
|
|
ch = *lpszStr;
|
|
|
|
|
|
|
|
if ((lpszIter = StrChrW(lpszStr, '&')))
|
|
|
|
{
|
2007-06-25 14:01:28 +02:00
|
|
|
lpszTmp = lpszIter + 1;
|
2011-06-15 10:07:55 +02:00
|
|
|
if (*lpszTmp)
|
2004-03-18 03:11:23 +01:00
|
|
|
{
|
|
|
|
if (*lpszTmp != '&')
|
|
|
|
ch = *lpszTmp;
|
|
|
|
|
2019-06-20 09:13:05 +02:00
|
|
|
memmove( lpszIter, lpszTmp, (lstrlenW(lpszTmp) + 1) * sizeof(WCHAR) );
|
2004-03-18 03:11:23 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return ch;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*************************************************************************
|
|
|
|
* @ [SHLWAPI.216]
|
2004-02-17 23:48:56 +01:00
|
|
|
*
|
2021-08-30 17:17:19 +02:00
|
|
|
* Convert an ANSI string to Unicode.
|
2004-02-17 23:48:56 +01:00
|
|
|
*
|
|
|
|
* PARAMS
|
2004-03-18 03:11:23 +01:00
|
|
|
* dwCp [I] Code page for the conversion
|
2021-08-30 17:17:19 +02:00
|
|
|
* lpSrcStr [I] Source ANSI string to convert
|
2004-02-17 23:48:56 +01:00
|
|
|
* lpDstStr [O] Destination for converted Unicode string
|
|
|
|
* iLen [I] Length of lpDstStr
|
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* The return value of the MultiByteToWideChar() function called on lpSrcStr.
|
|
|
|
*/
|
2004-03-18 03:11:23 +01:00
|
|
|
DWORD WINAPI SHAnsiToUnicodeCP(DWORD dwCp, LPCSTR lpSrcStr, LPWSTR lpDstStr, int iLen)
|
2004-02-17 23:48:56 +01:00
|
|
|
{
|
|
|
|
DWORD dwRet;
|
|
|
|
|
2004-03-18 03:11:23 +01:00
|
|
|
dwRet = MultiByteToWideChar(dwCp, 0, lpSrcStr, -1, lpDstStr, iLen);
|
2022-02-18 09:16:21 +01:00
|
|
|
TRACE("%s->%s,ret=%ld\n", debugstr_a(lpSrcStr), debugstr_w(lpDstStr), dwRet);
|
2004-02-17 23:48:56 +01:00
|
|
|
return dwRet;
|
|
|
|
}
|
|
|
|
|
2004-03-18 03:11:23 +01:00
|
|
|
/*************************************************************************
|
|
|
|
* @ [SHLWAPI.215]
|
|
|
|
*
|
2021-08-30 17:17:19 +02:00
|
|
|
* Convert an ANSI string to Unicode.
|
2004-03-18 03:11:23 +01:00
|
|
|
*
|
|
|
|
* PARAMS
|
2021-08-30 17:17:19 +02:00
|
|
|
* lpSrcStr [I] Source ANSI string to convert
|
2004-03-18 03:11:23 +01:00
|
|
|
* lpDstStr [O] Destination for converted Unicode string
|
|
|
|
* iLen [I] Length of lpDstStr
|
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* The return value of the MultiByteToWideChar() function called on lpSrcStr.
|
|
|
|
*
|
|
|
|
* NOTES
|
|
|
|
* This function simply calls SHAnsiToUnicodeCP with code page CP_ACP.
|
|
|
|
*/
|
|
|
|
DWORD WINAPI SHAnsiToUnicode(LPCSTR lpSrcStr, LPWSTR lpDstStr, int iLen)
|
|
|
|
{
|
|
|
|
return SHAnsiToUnicodeCP(CP_ACP, lpSrcStr, lpDstStr, iLen);
|
|
|
|
}
|
|
|
|
|
2004-02-17 23:48:56 +01:00
|
|
|
/*************************************************************************
|
|
|
|
* @ [SHLWAPI.218]
|
|
|
|
*
|
2021-08-30 17:17:19 +02:00
|
|
|
* Convert a Unicode string to ANSI.
|
2004-02-17 23:48:56 +01:00
|
|
|
*
|
|
|
|
* PARAMS
|
|
|
|
* CodePage [I] Code page to use for the conversion
|
|
|
|
* lpSrcStr [I] Source Unicode string to convert
|
2021-08-30 17:17:19 +02:00
|
|
|
* lpDstStr [O] Destination for converted ANSI string
|
2009-06-30 22:32:52 +02:00
|
|
|
* dstlen [I] Length of buffer at lpDstStr
|
2004-02-17 23:48:56 +01:00
|
|
|
*
|
|
|
|
* RETURNS
|
2009-06-30 22:32:52 +02:00
|
|
|
* Success: The length in bytes of the result at lpDstStr (including the terminator)
|
|
|
|
* Failure: When using CP_UTF8, CP_UTF7 or 0xc350 as codePage, 0 is returned and
|
|
|
|
* the result is not nul-terminated.
|
|
|
|
* When using a different codepage, the length in bytes of the truncated
|
|
|
|
* result at lpDstStr (including the terminator) is returned and
|
|
|
|
* lpDstStr is always nul-terminated.
|
|
|
|
*
|
2004-02-17 23:48:56 +01:00
|
|
|
*/
|
2009-06-30 22:32:52 +02:00
|
|
|
DWORD WINAPI SHUnicodeToAnsiCP(UINT CodePage, LPCWSTR lpSrcStr, LPSTR lpDstStr, int dstlen)
|
2004-02-17 23:48:56 +01:00
|
|
|
{
|
2004-04-20 03:12:17 +02:00
|
|
|
static const WCHAR emptyW[] = { '\0' };
|
2004-02-17 23:48:56 +01:00
|
|
|
int len , reqLen;
|
|
|
|
LPSTR mem;
|
|
|
|
|
2009-06-30 22:32:52 +02:00
|
|
|
if (!lpDstStr || !dstlen)
|
2004-02-17 23:48:56 +01:00
|
|
|
return 0;
|
|
|
|
|
|
|
|
if (!lpSrcStr)
|
|
|
|
lpSrcStr = emptyW;
|
|
|
|
|
|
|
|
*lpDstStr = '\0';
|
|
|
|
|
2019-06-20 09:13:05 +02:00
|
|
|
len = lstrlenW(lpSrcStr) + 1;
|
2004-02-17 23:48:56 +01:00
|
|
|
|
|
|
|
switch (CodePage)
|
|
|
|
{
|
|
|
|
case CP_WINUNICODE:
|
|
|
|
CodePage = CP_UTF8; /* Fall through... */
|
|
|
|
case 0x0000C350: /* FIXME: CP_ #define */
|
|
|
|
case CP_UTF7:
|
|
|
|
case CP_UTF8:
|
|
|
|
{
|
|
|
|
DWORD dwMode = 0;
|
2009-06-30 22:32:52 +02:00
|
|
|
INT lenW = len - 1;
|
|
|
|
INT needed = dstlen - 1;
|
|
|
|
HRESULT hr;
|
2004-02-17 23:48:56 +01:00
|
|
|
|
2009-06-30 22:32:52 +02:00
|
|
|
/* try the user supplied buffer first */
|
|
|
|
hr = ConvertINetUnicodeToMultiByte(&dwMode, CodePage, lpSrcStr, &lenW, lpDstStr, &needed);
|
|
|
|
if (hr == S_OK)
|
2004-02-17 23:48:56 +01:00
|
|
|
{
|
2009-06-30 22:32:52 +02:00
|
|
|
lpDstStr[needed] = '\0';
|
|
|
|
return needed + 1;
|
|
|
|
}
|
2004-02-17 23:48:56 +01:00
|
|
|
|
2009-06-30 22:32:52 +02:00
|
|
|
/* user buffer too small. exclude termination and copy as much as possible */
|
|
|
|
lenW = len;
|
|
|
|
hr = ConvertINetUnicodeToMultiByte(&dwMode, CodePage, lpSrcStr, &lenW, NULL, &needed);
|
|
|
|
needed++;
|
|
|
|
mem = HeapAlloc(GetProcessHeap(), 0, needed);
|
|
|
|
if (!mem)
|
|
|
|
return 0;
|
2004-02-17 23:48:56 +01:00
|
|
|
|
2009-06-30 22:32:52 +02:00
|
|
|
hr = ConvertINetUnicodeToMultiByte(&dwMode, CodePage, lpSrcStr, &len, mem, &needed);
|
|
|
|
if (hr == S_OK)
|
|
|
|
{
|
|
|
|
reqLen = SHTruncateString(mem, dstlen);
|
|
|
|
if (reqLen > 0) memcpy(lpDstStr, mem, reqLen-1);
|
2004-02-17 23:48:56 +01:00
|
|
|
}
|
2009-06-30 22:32:52 +02:00
|
|
|
HeapFree(GetProcessHeap(), 0, mem);
|
|
|
|
return 0;
|
2004-02-17 23:48:56 +01:00
|
|
|
}
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2009-06-30 22:32:52 +02:00
|
|
|
/* try the user supplied buffer first */
|
|
|
|
reqLen = WideCharToMultiByte(CodePage, 0, lpSrcStr, len, lpDstStr, dstlen, NULL, NULL);
|
2004-02-17 23:48:56 +01:00
|
|
|
|
|
|
|
if (!reqLen && GetLastError() == ERROR_INSUFFICIENT_BUFFER)
|
|
|
|
{
|
|
|
|
reqLen = WideCharToMultiByte(CodePage, 0, lpSrcStr, len, NULL, 0, NULL, NULL);
|
|
|
|
if (reqLen)
|
|
|
|
{
|
2005-03-24 22:01:35 +01:00
|
|
|
mem = HeapAlloc(GetProcessHeap(), 0, reqLen);
|
2004-02-17 23:48:56 +01:00
|
|
|
if (mem)
|
|
|
|
{
|
2015-03-19 22:11:46 +01:00
|
|
|
WideCharToMultiByte(CodePage, 0, lpSrcStr, len, mem, reqLen, NULL, NULL);
|
2004-02-17 23:48:56 +01:00
|
|
|
|
2009-06-30 22:32:52 +02:00
|
|
|
reqLen = SHTruncateString(mem, dstlen -1);
|
2004-02-17 23:48:56 +01:00
|
|
|
reqLen++;
|
|
|
|
|
2009-06-30 22:32:52 +02:00
|
|
|
lstrcpynA(lpDstStr, mem, reqLen);
|
2004-02-17 23:48:56 +01:00
|
|
|
HeapFree(GetProcessHeap(), 0, mem);
|
2009-06-30 22:32:52 +02:00
|
|
|
lpDstStr[reqLen-1] = '\0';
|
2004-02-17 23:48:56 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return reqLen;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*************************************************************************
|
|
|
|
* @ [SHLWAPI.217]
|
|
|
|
*
|
2021-08-30 17:17:19 +02:00
|
|
|
* Convert a Unicode string to ANSI.
|
2004-02-17 23:48:56 +01:00
|
|
|
*
|
|
|
|
* PARAMS
|
|
|
|
* lpSrcStr [I] Source Unicode string to convert
|
2021-08-30 17:17:19 +02:00
|
|
|
* lpDstStr [O] Destination for converted ANSI string
|
2004-02-17 23:48:56 +01:00
|
|
|
* iLen [O] Length of lpDstStr in characters
|
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* See SHUnicodeToAnsiCP
|
|
|
|
|
|
|
|
* NOTES
|
|
|
|
* This function simply calls SHUnicodeToAnsiCP() with CodePage = CP_ACP.
|
|
|
|
*/
|
|
|
|
INT WINAPI SHUnicodeToAnsi(LPCWSTR lpSrcStr, LPSTR lpDstStr, INT iLen)
|
|
|
|
{
|
2009-06-30 22:32:52 +02:00
|
|
|
return SHUnicodeToAnsiCP(CP_ACP, lpSrcStr, lpDstStr, iLen);
|
2004-02-17 23:48:56 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/*************************************************************************
|
|
|
|
* @ [SHLWAPI.364]
|
|
|
|
*
|
2021-08-30 17:17:19 +02:00
|
|
|
* Determine if an ANSI string converts to Unicode and back identically.
|
2004-02-17 23:48:56 +01:00
|
|
|
*
|
|
|
|
* PARAMS
|
|
|
|
* lpSrcStr [I] Source Unicode string to convert
|
2021-08-30 17:17:19 +02:00
|
|
|
* lpDst [O] Destination for resulting ANSI string
|
2004-02-17 23:48:56 +01:00
|
|
|
* iLen [I] Length of lpDst in characters
|
|
|
|
*
|
|
|
|
* RETURNS
|
2021-08-30 17:17:19 +02:00
|
|
|
* TRUE, since ANSI strings always convert identically.
|
2004-02-17 23:48:56 +01:00
|
|
|
*/
|
|
|
|
BOOL WINAPI DoesStringRoundTripA(LPCSTR lpSrcStr, LPSTR lpDst, INT iLen)
|
|
|
|
{
|
|
|
|
lstrcpynA(lpDst, lpSrcStr, iLen);
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*************************************************************************
|
|
|
|
* @ [SHLWAPI.365]
|
|
|
|
*
|
2021-08-30 17:17:19 +02:00
|
|
|
* Determine if a Unicode string converts to ANSI and back identically.
|
2004-02-17 23:48:56 +01:00
|
|
|
*
|
|
|
|
* PARAMS
|
|
|
|
* lpSrcStr [I] Source Unicode string to convert
|
2021-08-30 17:17:19 +02:00
|
|
|
* lpDst [O] Destination for resulting ANSI string
|
2004-02-17 23:48:56 +01:00
|
|
|
* iLen [I] Length of lpDst in characters
|
|
|
|
*
|
|
|
|
* RETURNS
|
2021-08-30 17:17:19 +02:00
|
|
|
* TRUE, if lpSrcStr converts to ANSI and back identically,
|
2004-02-17 23:48:56 +01:00
|
|
|
* FALSE otherwise.
|
|
|
|
*/
|
|
|
|
BOOL WINAPI DoesStringRoundTripW(LPCWSTR lpSrcStr, LPSTR lpDst, INT iLen)
|
|
|
|
{
|
|
|
|
WCHAR szBuff[MAX_PATH];
|
|
|
|
|
|
|
|
SHUnicodeToAnsi(lpSrcStr, lpDst, iLen);
|
|
|
|
SHAnsiToUnicode(lpDst, szBuff, MAX_PATH);
|
2019-06-20 09:13:05 +02:00
|
|
|
return !wcscmp(lpSrcStr, szBuff);
|
2004-02-17 23:48:56 +01:00
|
|
|
}
|