2 * Helper functions for debugging
4 * Copyright 1998, 2002 Juergen Schmied
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
30 #include "wine/debug.h"
33 #include "shell32_main.h"
36 WINE_DEFAULT_DEBUG_CHANNEL(pidl);
39 LPITEMIDLIST _dbg_ILGetNext(LPCITEMIDLIST pidl)
48 return (LPITEMIDLIST) (((LPBYTE)pidl)+len);
55 BOOL _dbg_ILIsDesktop(LPCITEMIDLIST pidl)
57 return ( !pidl || (pidl && pidl->mkid.cb == 0x00) );
61 LPPIDLDATA _dbg_ILGetDataPointer(LPCITEMIDLIST pidl)
63 if(pidl && pidl->mkid.cb != 0x00)
64 return (LPPIDLDATA) &(pidl->mkid.abID);
69 LPSTR _dbg_ILGetTextPointer(LPCITEMIDLIST pidl)
71 LPPIDLDATA pdata =_dbg_ILGetDataPointer(pidl);
86 return (LPSTR)&(pdata->u.drive.szDriveName);
93 return (LPSTR)&(pdata->u.file.szNames);
100 return (LPSTR)&(pdata->u.network.szNames);
107 LPSTR _dbg_ILGetSTextPointer(LPCITEMIDLIST pidl)
109 LPPIDLDATA pdata =_dbg_ILGetDataPointer(pidl);
119 return (LPSTR)(pdata->u.file.szNames + strlen (pdata->u.file.szNames) + 1);
122 return (LPSTR)(pdata->u.network.szNames + strlen (pdata->u.network.szNames) + 1);
129 IID* _dbg_ILGetGUIDPointer(LPCITEMIDLIST pidl)
131 LPPIDLDATA pdata =_ILGetDataPointer(pidl);
139 return &(pdata->u.guid.guid);
146 DWORD _dbg_ILSimpleGetText (LPCITEMIDLIST pidl, LPSTR szOut, UINT uOutSize)
151 char szTemp[MAX_PATH];
158 if (_dbg_ILIsDesktop(pidl))
161 if (szOut) strncpy(szOut, "Desktop", uOutSize);
162 dwReturn = strlen ("Desktop");
164 else if (( szSrc = _dbg_ILGetTextPointer(pidl) ))
167 if (szOut) strncpy(szOut, szSrc, uOutSize);
168 dwReturn = strlen(szSrc);
170 else if (( riid = _dbg_ILGetGUIDPointer(pidl) ))
173 sprintf( szOut, "{%08lx-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x}",
174 riid->Data1, riid->Data2, riid->Data3,
175 riid->Data4[0], riid->Data4[1], riid->Data4[2], riid->Data4[3],
176 riid->Data4[4], riid->Data4[5], riid->Data4[6], riid->Data4[7] );
177 dwReturn = strlen (szTemp);
185 void pdump (LPCITEMIDLIST pidl)
187 LPCITEMIDLIST pidltemp = pidl;
189 if (!TRACE_ON(pidl)) return;
193 MESSAGE ("-------- pidl=NULL (Desktop)\n");
197 MESSAGE ("-------- pidl=%p\n", pidl);
198 if (pidltemp->mkid.cb)
203 LPPIDLDATA pData = _dbg_ILGetDataPointer(pidltemp);
204 DWORD type = pData->type;
205 LPSTR szLongName = _dbg_ILGetTextPointer(pidltemp);
206 LPSTR szShortName = _dbg_ILGetSTextPointer(pidltemp);
207 char szName[MAX_PATH];
209 _dbg_ILSimpleGetText(pidltemp, szName, MAX_PATH);
210 if( PT_FOLDER == type || PT_VALUE == type)
211 dwAttrib = pData->u.file.uFileAttribs;
213 MESSAGE ("[%p] size=%04u type=%lx attr=0x%08lx name=\"%s\" (%s,%s)\n",
214 pidltemp, pidltemp->mkid.cb,type,dwAttrib,szName,debugstr_a(szLongName), debugstr_a(szShortName));
216 pidltemp = _dbg_ILGetNext(pidltemp);
218 } while (pidltemp && pidltemp->mkid.cb);
222 MESSAGE ("empty pidl (Desktop)\n");
228 static void dump_pidl_hex( LPCITEMIDLIST pidl )
230 const unsigned char *p = (const unsigned char *)pidl;
231 const int max_bytes = 0x80, max_line = 0x10;
232 char szHex[max_line*3+1], szAscii[max_line+1];
240 sprintf( &szHex[ (i%max_line)*3 ], "%02X ", p[i] );
241 szAscii[ (i%max_line) ] = isprint( p[i] ) ? p[i] : '.';
243 /* print out at the end of each line and when we're finished */
244 if( i!=(n-1) && (i%max_line) != (max_line-1) )
246 szAscii[ (i%max_line)+1 ] = 0;
247 DPRINTF("%-*s %s\n", max_line*3, szHex, szAscii );
251 BOOL pcheck( LPCITEMIDLIST pidl )
254 LPCITEMIDLIST pidltemp = pidl;
256 while( pidltemp && pidltemp->mkid.cb )
258 type = _dbg_ILGetDataPointer(pidltemp)->type;
281 ERR("unknown IDLIST %p [%p] size=%u type=%lx\n",
282 pidl, pidltemp, pidltemp->mkid.cb,type );
283 dump_pidl_hex( pidltemp );
286 pidltemp = _dbg_ILGetNext(pidltemp);
291 static char shdebugstr_buf1[100];
292 static char shdebugstr_buf2[100];
293 static char * shdebugstr_buf = shdebugstr_buf1;
298 } InterfaceDesc[] = {
299 {&IID_IUnknown, "IID_IUnknown"},
300 {&IID_IClassFactory, "IID_IClassFactory"},
301 {&IID_IShellView, "IID_IShellView"},
302 {&IID_IOleCommandTarget, "IID_IOleCommandTarget"},
303 {&IID_IDropTarget, "IID_IDropTarget"},
304 {&IID_IDropSource, "IID_IDropSource"},
305 {&IID_IViewObject, "IID_IViewObject"},
306 {&IID_IContextMenu, "IID_IContextMenu"},
307 {&IID_IShellExtInit, "IID_IShellExtInit"},
308 {&IID_IShellFolder, "IID_IShellFolder"},
309 {&IID_IShellFolder2, "IID_IShellFolder2"},
310 {&IID_IPersist, "IID_IPersist"},
311 {&IID_IPersistFolder, "IID_IPersistFolder"},
312 {&IID_IPersistFolder2, "IID_IPersistFolder2"},
313 {&IID_IPersistFolder3, "IID_IPersistFolder3"},
314 {&IID_IExtractIconA, "IID_IExtractIconA"},
315 {&IID_IExtractIconW, "IID_IExtractIconW"},
316 {&IID_IDataObject, "IID_IDataObject"},
317 {&IID_IAutoComplete, "IID_IAutoComplete"},
318 {&IID_IAutoComplete2, "IID_IAutoComplete2"},
321 const char * shdebugstr_guid( const struct _GUID *id )
327 shdebugstr_buf = (shdebugstr_buf == shdebugstr_buf1) ? shdebugstr_buf2 : shdebugstr_buf1;
330 strcpy (shdebugstr_buf, "(null)");
332 for (i=0;InterfaceDesc[i].riid && !name;i++) {
333 if (IsEqualIID(InterfaceDesc[i].riid, id)) name = InterfaceDesc[i].name;
336 if (HCR_GetClassNameA(id, clsidbuf, 100))
340 sprintf( shdebugstr_buf, "\n\t{%08lx-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x} (%s)",
341 id->Data1, id->Data2, id->Data3,
342 id->Data4[0], id->Data4[1], id->Data4[2], id->Data4[3],
343 id->Data4[4], id->Data4[5], id->Data4[6], id->Data4[7], name ? name : "unknown" );
345 return shdebugstr_buf;