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
25 #define NONAMELESSUNION
26 #define NONAMELESSSTRUCT
38 #include "shell32_main.h"
39 #include "undocshell.h"
40 #include "wine/unicode.h"
41 #include "wine/debug.h"
43 WINE_DEFAULT_DEBUG_CHANNEL(shell
);
45 /************************* STRRET functions ****************************/
49 * These routines are identical to StrRetToBuf[AW] in dlls/shlwapi/string.c.
50 * They were duplicated here because not every version of Shlwapi.dll exports
51 * StrRetToBuf[AW]. If you change one routine, change them both. YOU HAVE BEEN
56 HRESULT WINAPI
StrRetToStrNA (LPVOID dest
, DWORD len
, LPSTRRET src
, const ITEMIDLIST
*pidl
)
58 TRACE("dest=%p len=0x%lx strret=%p(%s) pidl=%p\n",
60 (src
->uType
== STRRET_WSTR
) ? "STRRET_WSTR" :
61 (src
->uType
== STRRET_CSTR
) ? "STRRET_CSTR" :
62 (src
->uType
== STRRET_OFFSET
) ? "STRRET_OFFSET" : "STRRET_???",
68 WideCharToMultiByte(CP_ACP
, 0, src
->u
.pOleStr
, -1, (LPSTR
)dest
, len
, NULL
, NULL
);
69 CoTaskMemFree(src
->u
.pOleStr
);
73 lstrcpynA((LPSTR
)dest
, src
->u
.cStr
, len
);
77 lstrcpynA((LPSTR
)dest
, ((LPCSTR
)&pidl
->mkid
)+src
->u
.uOffset
, len
);
81 FIXME("unknown type!\n");
82 if (len
) *(LPSTR
)dest
= '\0';
85 TRACE("-- %s\n", debugstr_a(dest
) );
89 /************************************************************************/
91 HRESULT WINAPI
StrRetToStrNW (LPVOID dest
, DWORD len
, LPSTRRET src
, const ITEMIDLIST
*pidl
)
93 TRACE("dest=%p len=0x%lx strret=%p(%s) pidl=%p\n",
95 (src
->uType
== STRRET_WSTR
) ? "STRRET_WSTR" :
96 (src
->uType
== STRRET_CSTR
) ? "STRRET_CSTR" :
97 (src
->uType
== STRRET_OFFSET
) ? "STRRET_OFFSET" : "STRRET_???",
103 lstrcpynW((LPWSTR
)dest
, src
->u
.pOleStr
, len
);
104 CoTaskMemFree(src
->u
.pOleStr
);
108 if (!MultiByteToWideChar( CP_ACP
, 0, src
->u
.cStr
, -1, dest
, len
) && len
)
109 ((LPWSTR
)dest
)[len
-1] = 0;
113 if (!MultiByteToWideChar( CP_ACP
, 0, ((LPCSTR
)&pidl
->mkid
)+src
->u
.uOffset
, -1, dest
, len
) && len
)
114 ((LPWSTR
)dest
)[len
-1] = 0;
118 FIXME("unknown type!\n");
119 if (len
) *(LPWSTR
)dest
= '\0';
126 /*************************************************************************
127 * StrRetToStrN [SHELL32.96]
129 * converts a STRRET to a normal string
132 * the pidl is for STRRET OFFSET
134 HRESULT WINAPI
StrRetToStrNAW (LPVOID dest
, DWORD len
, LPSTRRET src
, const ITEMIDLIST
*pidl
)
136 if(SHELL_OsIsUnicode())
137 return StrRetToStrNW (dest
, len
, src
, pidl
);
138 return StrRetToStrNA (dest
, len
, src
, pidl
);
141 /************************* OLESTR functions ****************************/
143 /************************************************************************
144 * StrToOleStr [SHELL32.163]
147 int WINAPI
StrToOleStrA (LPWSTR lpWideCharStr
, LPCSTR lpMultiByteString
)
149 TRACE("(%p, %p %s)\n",
150 lpWideCharStr
, lpMultiByteString
, debugstr_a(lpMultiByteString
));
152 return MultiByteToWideChar(0, 0, lpMultiByteString
, -1, lpWideCharStr
, MAX_PATH
);
155 int WINAPI
StrToOleStrW (LPWSTR lpWideCharStr
, LPCWSTR lpWString
)
157 TRACE("(%p, %p %s)\n",
158 lpWideCharStr
, lpWString
, debugstr_w(lpWString
));
160 strcpyW (lpWideCharStr
, lpWString
);
161 return strlenW(lpWideCharStr
);
164 BOOL WINAPI
StrToOleStrAW (LPWSTR lpWideCharStr
, LPCVOID lpString
)
166 if (SHELL_OsIsUnicode())
167 return StrToOleStrW (lpWideCharStr
, lpString
);
168 return StrToOleStrA (lpWideCharStr
, lpString
);
171 /*************************************************************************
172 * StrToOleStrN [SHELL32.79]
173 * lpMulti, nMulti, nWide [IN]
176 BOOL WINAPI
StrToOleStrNA (LPWSTR lpWide
, INT nWide
, LPCSTR lpStrA
, INT nStr
)
178 TRACE("(%p, %x, %s, %x)\n", lpWide
, nWide
, debugstr_an(lpStrA
,nStr
), nStr
);
179 return MultiByteToWideChar (0, 0, lpStrA
, nStr
, lpWide
, nWide
);
181 BOOL WINAPI
StrToOleStrNW (LPWSTR lpWide
, INT nWide
, LPCWSTR lpStrW
, INT nStr
)
183 TRACE("(%p, %x, %s, %x)\n", lpWide
, nWide
, debugstr_wn(lpStrW
, nStr
), nStr
);
185 if (lstrcpynW (lpWide
, lpStrW
, nWide
))
186 { return lstrlenW (lpWide
);
191 BOOL WINAPI
StrToOleStrNAW (LPWSTR lpWide
, INT nWide
, LPCVOID lpStr
, INT nStr
)
193 if (SHELL_OsIsUnicode())
194 return StrToOleStrNW (lpWide
, nWide
, lpStr
, nStr
);
195 return StrToOleStrNA (lpWide
, nWide
, lpStr
, nStr
);
198 /*************************************************************************
199 * OleStrToStrN [SHELL32.78]
201 BOOL WINAPI
OleStrToStrNA (LPSTR lpStr
, INT nStr
, LPCWSTR lpOle
, INT nOle
)
203 TRACE("(%p, %x, %s, %x)\n", lpStr
, nStr
, debugstr_wn(lpOle
,nOle
), nOle
);
204 return WideCharToMultiByte (0, 0, lpOle
, nOle
, lpStr
, nStr
, NULL
, NULL
);
207 BOOL WINAPI
OleStrToStrNW (LPWSTR lpwStr
, INT nwStr
, LPCWSTR lpOle
, INT nOle
)
209 TRACE("(%p, %x, %s, %x)\n", lpwStr
, nwStr
, debugstr_wn(lpOle
,nOle
), nOle
);
211 if (lstrcpynW ( lpwStr
, lpOle
, nwStr
))
212 { return lstrlenW (lpwStr
);
217 BOOL WINAPI
OleStrToStrNAW (LPVOID lpOut
, INT nOut
, LPCVOID lpIn
, INT nIn
)
219 if (SHELL_OsIsUnicode())
220 return OleStrToStrNW (lpOut
, nOut
, lpIn
, nIn
);
221 return OleStrToStrNA (lpOut
, nOut
, lpIn
, nIn
);
225 /*************************************************************************
226 * CheckEscapesA [SHELL32.@]
228 * Checks a string for special characters which are not allowed in a path
229 * and encloses it in quotes if that is the case.
232 * string [I/O] string to check and on return eventually quoted
233 * len [I] length of string
236 * length of actual string
239 * Not really sure if this function returns actually a value at all.
241 DWORD WINAPI
CheckEscapesA(
242 LPSTR string
, /* [I/O] string to check ??*/
243 DWORD len
) /* [I] is 0 */
248 TRACE("(%s %ld)\n", debugstr_a(string
), len
);
249 wString
= (LPWSTR
)LocalAlloc(LPTR
, len
* sizeof(WCHAR
));
252 MultiByteToWideChar(CP_ACP
, 0, string
, len
, wString
, len
);
253 ret
= CheckEscapesW(wString
, len
);
254 WideCharToMultiByte(CP_ACP
, 0, wString
, len
, string
, len
, NULL
, NULL
);
260 static const WCHAR strEscapedChars
[] = {' ','"',',',';','^',0};
262 /*************************************************************************
263 * CheckEscapesW [SHELL32.@]
267 DWORD WINAPI
CheckEscapesW(
271 DWORD size
= lstrlenW(string
);
274 TRACE("(%s %ld) stub\n", debugstr_w(string
), len
);
276 if (StrPBrkW(string
, strEscapedChars
) && size
+ 2 <= len
)
278 s
= &string
[size
- 1];
279 d
= &string
[size
+ 2];