ReactOS 0.4.15-dev-7924-g5949c20
shellstring.c
Go to the documentation of this file.
1/*
2 * Copyright 2000 Juergen Schmied
3 *
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
8 *
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
13 *
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
17 */
18
19#define WIN32_NO_STATUS
20#define _INC_WINDOWS
21#define NONAMELESSUNION
22#define NONAMELESSSTRUCT
23
24#include <windef.h>
25#include <winbase.h>
26#include <shlobj.h>
27#include <shlwapi.h>
28#include <undocshell.h>
29#include <shlwapi_undoc.h>
30#include <wine/unicode.h>
31#include <wine/debug.h>
32
33#include "shell32_main.h"
34
36
37/************************* STRRET functions ****************************/
38
39static const char *debugstr_strret(STRRET *s)
40{
41 switch (s->uType)
42 {
43 case STRRET_WSTR:
44 return "STRRET_WSTR";
45 case STRRET_CSTR:
46 return "STRRET_CSTR";
47 case STRRET_OFFSET:
48 return "STRRET_OFFSET";
49 default:
50 return "STRRET_???";
51 }
52}
53
55{
56 TRACE("dest=%p len=0x%x strret=%p(%s) pidl=%p\n", dest, len, src, debugstr_strret(src), pidl);
57
58 if (!dest)
59 return FALSE;
60
61 switch (src->uType)
62 {
63 case STRRET_WSTR:
64 WideCharToMultiByte(CP_ACP, 0, src->u.pOleStr, -1, dest, len, NULL, NULL);
65 CoTaskMemFree(src->u.pOleStr);
66 break;
67 case STRRET_CSTR:
68 lstrcpynA(dest, src->u.cStr, len);
69 break;
70 case STRRET_OFFSET:
71 lstrcpynA(dest, ((LPCSTR)&pidl->mkid)+src->u.uOffset, len);
72 break;
73 default:
74 FIXME("unknown type %u!\n", src->uType);
75 if (len)
76 *dest = '\0';
77 return FALSE;
78 }
79 TRACE("-- %s\n", debugstr_a(dest) );
80 return TRUE;
81}
82
83/************************************************************************/
84
86{
87 TRACE("dest=%p len=0x%x strret=%p(%s) pidl=%p\n", dest, len, src, debugstr_strret(src), pidl);
88
89 if (!dest)
90 return FALSE;
91
92 switch (src->uType)
93 {
94 case STRRET_WSTR:
95 lstrcpynW(dest, src->u.pOleStr, len);
96 CoTaskMemFree(src->u.pOleStr);
97 break;
98 case STRRET_CSTR:
99 if (!MultiByteToWideChar(CP_ACP, 0, src->u.cStr, -1, dest, len) && len)
100 dest[len-1] = 0;
101 break;
102 case STRRET_OFFSET:
103 if (!MultiByteToWideChar(CP_ACP, 0, ((LPCSTR)&pidl->mkid)+src->u.uOffset, -1, dest, len)
104 && len)
105 dest[len-1] = 0;
106 break;
107 default:
108 FIXME("unknown type %u!\n", src->uType);
109 if (len)
110 *dest = '\0';
111 return FALSE;
112 }
113 return TRUE;
114}
115
116
117/*************************************************************************
118 * StrRetToStrN [SHELL32.96]
119 *
120 * converts a STRRET to a normal string
121 *
122 * NOTES
123 * the pidl is for STRRET OFFSET
124 */
126{
128 return StrRetToStrNW(dest, len, src, pidl);
129 else
130 return StrRetToStrNA(dest, len, src, pidl);
131}
132
133/************************* OLESTR functions ****************************/
134
135/************************************************************************
136 * StrToOleStr [SHELL32.163]
137 *
138 */
139static int StrToOleStrA (LPWSTR lpWideCharStr, LPCSTR lpMultiByteString)
140{
141 TRACE("(%p, %p %s)\n",
142 lpWideCharStr, lpMultiByteString, debugstr_a(lpMultiByteString));
143
144 return MultiByteToWideChar(CP_ACP, 0, lpMultiByteString, -1, lpWideCharStr, MAX_PATH);
145
146}
147static int StrToOleStrW (LPWSTR lpWideCharStr, LPCWSTR lpWString)
148{
149 TRACE("(%p, %p %s)\n",
150 lpWideCharStr, lpWString, debugstr_w(lpWString));
151
152 strcpyW (lpWideCharStr, lpWString );
153 return strlenW(lpWideCharStr);
154}
155
156BOOL WINAPI StrToOleStrAW (LPWSTR lpWideCharStr, LPCVOID lpString)
157{
158 if (SHELL_OsIsUnicode())
159 return StrToOleStrW (lpWideCharStr, lpString);
160 return StrToOleStrA (lpWideCharStr, lpString);
161}
162
163/*************************************************************************
164 * StrToOleStrN [SHELL32.79]
165 * lpMulti, nMulti, nWide [IN]
166 * lpWide [OUT]
167 */
168static BOOL StrToOleStrNA (LPWSTR lpWide, INT nWide, LPCSTR lpStrA, INT nStr)
169{
170 TRACE("(%p, %x, %s, %x)\n", lpWide, nWide, debugstr_an(lpStrA,nStr), nStr);
171 return MultiByteToWideChar (CP_ACP, 0, lpStrA, nStr, lpWide, nWide);
172}
173static BOOL StrToOleStrNW (LPWSTR lpWide, INT nWide, LPCWSTR lpStrW, INT nStr)
174{
175 TRACE("(%p, %x, %s, %x)\n", lpWide, nWide, debugstr_wn(lpStrW, nStr), nStr);
176
177 if (lstrcpynW (lpWide, lpStrW, nWide))
178 { return lstrlenW (lpWide);
179 }
180 return FALSE;
181}
182
183BOOL WINAPI StrToOleStrNAW (LPWSTR lpWide, INT nWide, LPCVOID lpStr, INT nStr)
184{
185 if (SHELL_OsIsUnicode())
186 return StrToOleStrNW (lpWide, nWide, lpStr, nStr);
187 return StrToOleStrNA (lpWide, nWide, lpStr, nStr);
188}
189
190/*************************************************************************
191 * OleStrToStrN [SHELL32.78]
192 */
193static BOOL OleStrToStrNA (LPSTR lpStr, INT nStr, LPCWSTR lpOle, INT nOle)
194{
195 TRACE("(%p, %x, %s, %x)\n", lpStr, nStr, debugstr_wn(lpOle,nOle), nOle);
196 return WideCharToMultiByte (CP_ACP, 0, lpOle, nOle, lpStr, nStr, NULL, NULL);
197}
198
199static BOOL OleStrToStrNW (LPWSTR lpwStr, INT nwStr, LPCWSTR lpOle, INT nOle)
200{
201 TRACE("(%p, %x, %s, %x)\n", lpwStr, nwStr, debugstr_wn(lpOle,nOle), nOle);
202
203 if (lstrcpynW ( lpwStr, lpOle, nwStr))
204 { return lstrlenW (lpwStr);
205 }
206 return FALSE;
207}
208
210{
211 if (SHELL_OsIsUnicode())
212 return OleStrToStrNW (lpOut, nOut, lpIn, nIn);
213 return OleStrToStrNA (lpOut, nOut, lpIn, nIn);
214}
215
216
217/*************************************************************************
218 * CheckEscapesA [SHELL32.@]
219 *
220 * Checks a string for special characters which are not allowed in a path
221 * and encloses it in quotes if that is the case.
222 *
223 * PARAMS
224 * string [I/O] string to check and on return eventually quoted
225 * len [I] length of string
226 */
228 LPSTR string, /* [I/O] string to check ??*/
229 DWORD len) /* [I] is 0 */
230{
231 LPWSTR wString;
232 TRACE("(%s %d)\n", debugstr_a(string), len);
233
234 if (!string || !string[0])
235 return;
236
237 wString = LocalAlloc(LPTR, len * sizeof(WCHAR));
238 if (!wString)
239 return;
240
241 SHAnsiToUnicode(string, wString, len);
242 CheckEscapesW(wString, len);
243 SHUnicodeToAnsi(wString, string, len);
244 LocalFree(wString);
245}
246
247/*************************************************************************
248 * CheckEscapesW [SHELL32.@]
249 *
250 * See CheckEscapesA.
251 */
253 LPWSTR string,
254 DWORD len)
255{
256 DWORD size = lstrlenW(string);
257 LPWSTR s, d;
258
259 TRACE("(%s %d) stub\n", debugstr_w(string), len);
260
261 if (StrPBrkW(string, L" \",;^") && size + 2 <= len)
262 {
263 s = &string[size - 1];
264 d = &string[size + 2];
265 *d-- = 0;
266 *d-- = '"';
267 for (;d > string;)
268 *d-- = *s--;
269 *d = '"';
270 }
271}
#define WINE_DEFAULT_DEBUG_CHANNEL(t)
Definition: precomp.h:23
void shell(int argc, const char *argv[])
Definition: cmds.c:1231
#define FIXME(fmt,...)
Definition: debug.h:111
#define NULL
Definition: types.h:112
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
#define CP_ACP
Definition: compat.h:109
#define lstrcpynA
Definition: compat.h:751
static __inline const char * debugstr_an(const char *s, int n)
Definition: compat.h:55
#define MAX_PATH
Definition: compat.h:34
#define WideCharToMultiByte
Definition: compat.h:111
#define MultiByteToWideChar
Definition: compat.h:110
#define lstrcpynW
Definition: compat.h:738
#define lstrlenW
Definition: compat.h:750
LPWSTR WINAPI StrPBrkW(LPCWSTR lpszStr, LPCWSTR lpszMatch)
Definition: string.c:1284
DWORD WINAPI SHAnsiToUnicode(LPCSTR lpSrcStr, LPWSTR lpDstStr, int iLen)
Definition: string.c:2667
INT WINAPI SHUnicodeToAnsi(LPCWSTR lpSrcStr, LPSTR lpDstStr, INT iLen)
Definition: string.c:2791
unsigned int BOOL
Definition: ntddk_ex.h:94
unsigned long DWORD
Definition: ntddk_ex.h:95
GLdouble s
Definition: gl.h:2039
GLsizeiptr size
Definition: glext.h:5919
GLenum src
Definition: glext.h:6340
GLenum GLsizei len
Definition: glext.h:6722
HLOCAL NTAPI LocalAlloc(UINT uFlags, SIZE_T dwBytes)
Definition: heapmem.c:1390
HLOCAL NTAPI LocalFree(HLOCAL hMem)
Definition: heapmem.c:1594
VOID WINAPI CoTaskMemFree(LPVOID ptr)
Definition: ifs.c:442
#define d
Definition: ke_i.h:81
#define debugstr_a
Definition: kernel32.h:31
#define debugstr_wn
Definition: kernel32.h:33
#define debugstr_w
Definition: kernel32.h:32
char string[160]
Definition: util.h:11
static char * dest
Definition: rtl.c:135
#define L(x)
Definition: ntvdm.h:50
#define strlenW(s)
Definition: unicode.h:28
#define strcpyW(d, s)
Definition: unicode.h:29
static __inline BOOL SHELL_OsIsUnicode(void)
Definition: shell32_main.h:140
BOOL WINAPI StrRetToStrNW(LPWSTR dest, DWORD len, LPSTRRET src, const ITEMIDLIST *pidl)
Definition: shellstring.c:85
BOOL WINAPI StrRetToStrNA(LPSTR dest, DWORD len, LPSTRRET src, const ITEMIDLIST *pidl)
Definition: shellstring.c:54
BOOL WINAPI StrToOleStrAW(LPWSTR lpWideCharStr, LPCVOID lpString)
Definition: shellstring.c:156
static BOOL OleStrToStrNW(LPWSTR lpwStr, INT nwStr, LPCWSTR lpOle, INT nOle)
Definition: shellstring.c:199
static const char * debugstr_strret(STRRET *s)
Definition: shellstring.c:39
static int StrToOleStrW(LPWSTR lpWideCharStr, LPCWSTR lpWString)
Definition: shellstring.c:147
BOOL WINAPI OleStrToStrNAW(LPVOID lpOut, INT nOut, LPCVOID lpIn, INT nIn)
Definition: shellstring.c:209
VOID WINAPI CheckEscapesW(LPWSTR string, DWORD len)
Definition: shellstring.c:252
VOID WINAPI CheckEscapesA(LPSTR string, DWORD len)
Definition: shellstring.c:227
static BOOL StrToOleStrNW(LPWSTR lpWide, INT nWide, LPCWSTR lpStrW, INT nStr)
Definition: shellstring.c:173
BOOL WINAPI StrToOleStrNAW(LPWSTR lpWide, INT nWide, LPCVOID lpStr, INT nStr)
Definition: shellstring.c:183
BOOL WINAPI StrRetToStrNAW(LPVOID dest, DWORD len, LPSTRRET src, const ITEMIDLIST *pidl)
Definition: shellstring.c:125
static BOOL StrToOleStrNA(LPWSTR lpWide, INT nWide, LPCSTR lpStrA, INT nStr)
Definition: shellstring.c:168
static int StrToOleStrA(LPWSTR lpWideCharStr, LPCSTR lpMultiByteString)
Definition: shellstring.c:139
static BOOL OleStrToStrNA(LPSTR lpStr, INT nStr, LPCWSTR lpOle, INT nOle)
Definition: shellstring.c:193
@ STRRET_CSTR
Definition: shtypes.idl:87
@ STRRET_OFFSET
Definition: shtypes.idl:86
@ STRRET_WSTR
Definition: shtypes.idl:85
#define TRACE(s)
Definition: solgame.cpp:4
SHITEMID mkid
Definition: shtypes.idl:34
int32_t INT
Definition: typedefs.h:58
#define LPTR
Definition: winbase.h:381
CONST void * LPCVOID
Definition: windef.h:191
#define WINAPI
Definition: msvc.h:6
const char * LPCSTR
Definition: xmlstorage.h:183
char * LPSTR
Definition: xmlstorage.h:182
__wchar_t WCHAR
Definition: xmlstorage.h:180
WCHAR * LPWSTR
Definition: xmlstorage.h:184
const WCHAR * LPCWSTR
Definition: xmlstorage.h:185