2 * Copyright 2000 Juergen Schmied
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.
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.
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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
24 #define NONAMELESSUNION
25 #define NONAMELESSSTRUCT
33 #include "shell32_main.h"
34 #include "undocshell.h"
35 #include "wine/unicode.h"
36 #include "wine/debug.h"
38 WINE_DEFAULT_DEBUG_CHANNEL(shell);
40 /************************* STRRET functions ****************************/
44 * These routines are identical to StrRetToBuf[AW] in dlls/shlwapi/string.c.
45 * They were duplicated here because not every version of Shlwapi.dll exports
46 * StrRetToBuf[AW]. If you change one routine, change them both. YOU HAVE BEEN
51 HRESULT WINAPI StrRetToStrNA (LPVOID dest, DWORD len, LPSTRRET src, const ITEMIDLIST *pidl)
53 TRACE("dest=%p len=0x%lx strret=%p(%s) pidl=%p\n",
55 (src->uType == STRRET_WSTR) ? "STRRET_WSTR" :
56 (src->uType == STRRET_CSTR) ? "STRRET_CSTR" :
57 (src->uType == STRRET_OFFSET) ? "STRRET_OFFSET" : "STRRET_???",
63 WideCharToMultiByte(CP_ACP, 0, src->u.pOleStr, -1, (LPSTR)dest, len, NULL, NULL);
64 CoTaskMemFree(src->u.pOleStr);
68 lstrcpynA((LPSTR)dest, src->u.cStr, len);
72 lstrcpynA((LPSTR)dest, ((LPCSTR)&pidl->mkid)+src->u.uOffset, len);
76 FIXME("unknown type!\n");
77 if (len) *(LPSTR)dest = '\0';
80 TRACE("-- %s\n", debugstr_a(dest) );
84 /************************************************************************/
86 HRESULT WINAPI StrRetToStrNW (LPVOID dest, DWORD len, LPSTRRET src, const ITEMIDLIST *pidl)
88 TRACE("dest=%p len=0x%lx strret=%p(%s) pidl=%p\n",
90 (src->uType == STRRET_WSTR) ? "STRRET_WSTR" :
91 (src->uType == STRRET_CSTR) ? "STRRET_CSTR" :
92 (src->uType == STRRET_OFFSET) ? "STRRET_OFFSET" : "STRRET_???",
98 lstrcpynW((LPWSTR)dest, src->u.pOleStr, len);
99 CoTaskMemFree(src->u.pOleStr);
103 if (!MultiByteToWideChar( CP_ACP, 0, src->u.cStr, -1, dest, len ) && len)
104 ((LPWSTR)dest)[len-1] = 0;
108 if (!MultiByteToWideChar( CP_ACP, 0, ((LPCSTR)&pidl->mkid)+src->u.uOffset, -1, dest, len ) && len)
109 ((LPWSTR)dest)[len-1] = 0;
113 FIXME("unknown type!\n");
114 if (len) *(LPWSTR)dest = '\0';
121 /*************************************************************************
122 * StrRetToStrN [SHELL32.96]
124 * converts a STRRET to a normal string
127 * the pidl is for STRRET OFFSET
129 HRESULT WINAPI StrRetToStrNAW (LPVOID dest, DWORD len, LPSTRRET src, const ITEMIDLIST *pidl)
131 if(SHELL_OsIsUnicode())
132 return StrRetToStrNW (dest, len, src, pidl);
133 return StrRetToStrNA (dest, len, src, pidl);
136 /************************* OLESTR functions ****************************/
138 /************************************************************************
139 * StrToOleStr [SHELL32.163]
142 int WINAPI StrToOleStrA (LPWSTR lpWideCharStr, LPCSTR lpMultiByteString)
144 TRACE("(%p, %p %s)\n",
145 lpWideCharStr, lpMultiByteString, debugstr_a(lpMultiByteString));
147 return MultiByteToWideChar(0, 0, lpMultiByteString, -1, lpWideCharStr, MAX_PATH);
150 int WINAPI StrToOleStrW (LPWSTR lpWideCharStr, LPCWSTR lpWString)
152 TRACE("(%p, %p %s)\n",
153 lpWideCharStr, lpWString, debugstr_w(lpWString));
155 strcpyW (lpWideCharStr, lpWString );
156 return strlenW(lpWideCharStr);
159 BOOL WINAPI StrToOleStrAW (LPWSTR lpWideCharStr, LPCVOID lpString)
161 if (SHELL_OsIsUnicode())
162 return StrToOleStrW (lpWideCharStr, lpString);
163 return StrToOleStrA (lpWideCharStr, lpString);
166 /*************************************************************************
167 * StrToOleStrN [SHELL32.79]
168 * lpMulti, nMulti, nWide [IN]
171 BOOL WINAPI StrToOleStrNA (LPWSTR lpWide, INT nWide, LPCSTR lpStrA, INT nStr)
173 TRACE("(%p, %x, %s, %x)\n", lpWide, nWide, debugstr_an(lpStrA,nStr), nStr);
174 return MultiByteToWideChar (0, 0, lpStrA, nStr, lpWide, nWide);
176 BOOL WINAPI StrToOleStrNW (LPWSTR lpWide, INT nWide, LPCWSTR lpStrW, INT nStr)
178 TRACE("(%p, %x, %s, %x)\n", lpWide, nWide, debugstr_wn(lpStrW, nStr), nStr);
180 if (lstrcpynW (lpWide, lpStrW, nWide))
181 { return lstrlenW (lpWide);
186 BOOL WINAPI StrToOleStrNAW (LPWSTR lpWide, INT nWide, LPCVOID lpStr, INT nStr)
188 if (SHELL_OsIsUnicode())
189 return StrToOleStrNW (lpWide, nWide, lpStr, nStr);
190 return StrToOleStrNA (lpWide, nWide, lpStr, nStr);
193 /*************************************************************************
194 * OleStrToStrN [SHELL32.78]
196 BOOL WINAPI OleStrToStrNA (LPSTR lpStr, INT nStr, LPCWSTR lpOle, INT nOle)
198 TRACE("(%p, %x, %s, %x)\n", lpStr, nStr, debugstr_wn(lpOle,nOle), nOle);
199 return WideCharToMultiByte (0, 0, lpOle, nOle, lpStr, nStr, NULL, NULL);
202 BOOL WINAPI OleStrToStrNW (LPWSTR lpwStr, INT nwStr, LPCWSTR lpOle, INT nOle)
204 TRACE("(%p, %x, %s, %x)\n", lpwStr, nwStr, debugstr_wn(lpOle,nOle), nOle);
206 if (lstrcpynW ( lpwStr, lpOle, nwStr))
207 { return lstrlenW (lpwStr);
212 BOOL WINAPI OleStrToStrNAW (LPVOID lpOut, INT nOut, LPCVOID lpIn, INT nIn)
214 if (SHELL_OsIsUnicode())
215 return OleStrToStrNW (lpOut, nOut, lpIn, nIn);
216 return OleStrToStrNA (lpOut, nOut, lpIn, nIn);
220 /*************************************************************************
221 * CheckEscapesA [SHELL32.@]
223 * Checks a string for special characters which are not allowed in a path
224 * and encloses it in quotes if that is the case.
227 * string [I/O] string to check and on return eventually quoted
228 * len [I] length of string
231 * length of actual string
234 * Not really sure if this function returns actually a value at all.
236 DWORD WINAPI CheckEscapesA(
237 LPSTR string, /* [I/O] string to check ??*/
238 DWORD len) /* [I] is 0 */
243 TRACE("(%s %ld)\n", debugstr_a(string), len);
244 wString = (LPWSTR)LocalAlloc(LPTR, len * sizeof(WCHAR));
247 MultiByteToWideChar(CP_ACP, 0, string, len, wString, len);
248 ret = CheckEscapesW(wString, len);
249 WideCharToMultiByte(CP_ACP, 0, wString, len, string, len, NULL, NULL);
255 static const WCHAR strEscapedChars[] = {' ','"',',',';','^',0};
257 /*************************************************************************
258 * CheckEscapesW [SHELL32.@]
262 DWORD WINAPI CheckEscapesW(
266 DWORD size = lstrlenW(string);
269 TRACE("(%s %ld) stub\n", debugstr_w(string), len);
271 if (StrPBrkW(string, strEscapedChars) && size + 2 <= len)
273 s = &string[size - 1];
274 d = &string[size + 2];