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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
25 #define NONAMELESSUNION
36 #include "shell32_main.h"
37 #include "undocshell.h"
38 #include "wine/unicode.h"
39 #include "wine/debug.h"
41 WINE_DEFAULT_DEBUG_CHANNEL(shell
);
43 /************************* STRRET functions ****************************/
45 static const char *debugstr_strret(STRRET
*s
)
54 return "STRRET_OFFSET";
60 BOOL WINAPI
StrRetToStrNA(LPSTR dest
, DWORD len
, LPSTRRET src
, const ITEMIDLIST
*pidl
)
62 TRACE("dest=%p len=0x%x strret=%p(%s) pidl=%p\n", dest
, len
, src
, debugstr_strret(src
), pidl
);
70 WideCharToMultiByte(CP_ACP
, 0, src
->u
.pOleStr
, -1, dest
, len
, NULL
, NULL
);
71 CoTaskMemFree(src
->u
.pOleStr
);
74 lstrcpynA(dest
, src
->u
.cStr
, len
);
77 lstrcpynA(dest
, ((LPCSTR
)&pidl
->mkid
)+src
->u
.uOffset
, len
);
80 FIXME("unknown type %u!\n", src
->uType
);
85 TRACE("-- %s\n", debugstr_a(dest
) );
89 /************************************************************************/
91 BOOL WINAPI
StrRetToStrNW(LPWSTR dest
, DWORD len
, LPSTRRET src
, const ITEMIDLIST
*pidl
)
93 TRACE("dest=%p len=0x%x strret=%p(%s) pidl=%p\n", dest
, len
, src
, debugstr_strret(src
), pidl
);
101 lstrcpynW(dest
, src
->u
.pOleStr
, len
);
102 CoTaskMemFree(src
->u
.pOleStr
);
105 if (!MultiByteToWideChar(CP_ACP
, 0, src
->u
.cStr
, -1, dest
, len
) && len
)
109 if (!MultiByteToWideChar(CP_ACP
, 0, ((LPCSTR
)&pidl
->mkid
)+src
->u
.uOffset
, -1, dest
, len
)
114 FIXME("unknown type %u!\n", src
->uType
);
123 /*************************************************************************
124 * StrRetToStrN [SHELL32.96]
126 * converts a STRRET to a normal string
129 * the pidl is for STRRET OFFSET
131 BOOL WINAPI
StrRetToStrNAW(LPVOID dest
, DWORD len
, LPSTRRET src
, const ITEMIDLIST
*pidl
)
133 if(SHELL_OsIsUnicode())
134 return StrRetToStrNW(dest
, len
, src
, pidl
);
136 return StrRetToStrNA(dest
, len
, src
, pidl
);
139 /************************* OLESTR functions ****************************/
141 /************************************************************************
142 * StrToOleStr [SHELL32.163]
145 static int StrToOleStrA (LPWSTR lpWideCharStr
, LPCSTR lpMultiByteString
)
147 TRACE("(%p, %p %s)\n",
148 lpWideCharStr
, lpMultiByteString
, debugstr_a(lpMultiByteString
));
150 return MultiByteToWideChar(CP_ACP
, 0, lpMultiByteString
, -1, lpWideCharStr
, MAX_PATH
);
153 static int StrToOleStrW (LPWSTR lpWideCharStr
, LPCWSTR lpWString
)
155 TRACE("(%p, %p %s)\n",
156 lpWideCharStr
, lpWString
, debugstr_w(lpWString
));
158 strcpyW (lpWideCharStr
, lpWString
);
159 return strlenW(lpWideCharStr
);
162 BOOL WINAPI
StrToOleStrAW (LPWSTR lpWideCharStr
, LPCVOID lpString
)
164 if (SHELL_OsIsUnicode())
165 return StrToOleStrW (lpWideCharStr
, lpString
);
166 return StrToOleStrA (lpWideCharStr
, lpString
);
169 /*************************************************************************
170 * StrToOleStrN [SHELL32.79]
171 * lpMulti, nMulti, nWide [IN]
174 static BOOL
StrToOleStrNA (LPWSTR lpWide
, INT nWide
, LPCSTR lpStrA
, INT nStr
)
176 TRACE("(%p, %x, %s, %x)\n", lpWide
, nWide
, debugstr_an(lpStrA
,nStr
), nStr
);
177 return MultiByteToWideChar (CP_ACP
, 0, lpStrA
, nStr
, lpWide
, nWide
);
179 static BOOL
StrToOleStrNW (LPWSTR lpWide
, INT nWide
, LPCWSTR lpStrW
, INT nStr
)
181 TRACE("(%p, %x, %s, %x)\n", lpWide
, nWide
, debugstr_wn(lpStrW
, nStr
), nStr
);
183 if (lstrcpynW (lpWide
, lpStrW
, nWide
))
184 { return lstrlenW (lpWide
);
189 BOOL WINAPI
StrToOleStrNAW (LPWSTR lpWide
, INT nWide
, LPCVOID lpStr
, INT nStr
)
191 if (SHELL_OsIsUnicode())
192 return StrToOleStrNW (lpWide
, nWide
, lpStr
, nStr
);
193 return StrToOleStrNA (lpWide
, nWide
, lpStr
, nStr
);
196 /*************************************************************************
197 * OleStrToStrN [SHELL32.78]
199 static BOOL
OleStrToStrNA (LPSTR lpStr
, INT nStr
, LPCWSTR lpOle
, INT nOle
)
201 TRACE("(%p, %x, %s, %x)\n", lpStr
, nStr
, debugstr_wn(lpOle
,nOle
), nOle
);
202 return WideCharToMultiByte (CP_ACP
, 0, lpOle
, nOle
, lpStr
, nStr
, NULL
, NULL
);
205 static BOOL
OleStrToStrNW (LPWSTR lpwStr
, INT nwStr
, LPCWSTR lpOle
, INT nOle
)
207 TRACE("(%p, %x, %s, %x)\n", lpwStr
, nwStr
, debugstr_wn(lpOle
,nOle
), nOle
);
209 if (lstrcpynW ( lpwStr
, lpOle
, nwStr
))
210 { return lstrlenW (lpwStr
);
215 BOOL WINAPI
OleStrToStrNAW (LPVOID lpOut
, INT nOut
, LPCVOID lpIn
, INT nIn
)
217 if (SHELL_OsIsUnicode())
218 return OleStrToStrNW (lpOut
, nOut
, lpIn
, nIn
);
219 return OleStrToStrNA (lpOut
, nOut
, lpIn
, nIn
);
223 /*************************************************************************
224 * CheckEscapesA [SHELL32.@]
226 * Checks a string for special characters which are not allowed in a path
227 * and encloses it in quotes if that is the case.
230 * string [I/O] string to check and on return eventually quoted
231 * len [I] length of string
234 * length of actual string
237 * Not really sure if this function returns actually a value at all.
239 DWORD WINAPI
CheckEscapesA(
240 LPSTR string
, /* [I/O] string to check ??*/
241 DWORD len
) /* [I] is 0 */
246 TRACE("(%s %d)\n", debugstr_a(string
), len
);
247 wString
= LocalAlloc(LPTR
, len
* sizeof(WCHAR
));
250 MultiByteToWideChar(CP_ACP
, 0, string
, len
, wString
, len
);
251 ret
= CheckEscapesW(wString
, len
);
252 WideCharToMultiByte(CP_ACP
, 0, wString
, len
, string
, len
, NULL
, NULL
);
258 static const WCHAR strEscapedChars
[] = {' ','"',',',';','^',0};
260 /*************************************************************************
261 * CheckEscapesW [SHELL32.@]
265 DWORD WINAPI
CheckEscapesW(
269 DWORD size
= lstrlenW(string
);
272 TRACE("(%s %d) stub\n", debugstr_w(string
), len
);
274 if (StrPBrkW(string
, strEscapedChars
) && size
+ 2 <= len
)
276 s
= &string
[size
- 1];
277 d
= &string
[size
+ 2];