SHCoCreateInstance is now documented (spotted by Francois Gouget).
[wine/wine-kai.git] / dlls / shell32 / debughlp.c
blobbaacf7b752b3e86d09213a569212504d34e4f2eb
1 /*
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
21 #include <ctype.h>
22 #include <stdlib.h>
23 #include <string.h>
24 #include <stdio.h>
25 #include "windef.h"
26 #include "wingdi.h"
27 #include "pidl.h"
28 #include "shlguid.h"
29 #include "wine/debug.h"
30 #include "debughlp.h"
31 #include "docobj.h"
32 #include "shell32_main.h"
35 WINE_DEFAULT_DEBUG_CHANNEL(pidl);
37 LPITEMIDLIST _dbg_ILGetNext(LPCITEMIDLIST pidl)
39 WORD len;
41 if(pidl)
43 len = pidl->mkid.cb;
44 if (len)
46 return (LPITEMIDLIST) (((LPBYTE)pidl)+len);
49 return NULL;
52 BOOL _dbg_ILIsDesktop(LPCITEMIDLIST pidl)
54 return ( !pidl || (pidl && pidl->mkid.cb == 0x00) );
57 LPPIDLDATA _dbg_ILGetDataPointer(LPCITEMIDLIST pidl)
59 if(pidl && pidl->mkid.cb != 0x00)
60 return (LPPIDLDATA) &(pidl->mkid.abID);
61 return NULL;
64 LPSTR _dbg_ILGetTextPointer(LPCITEMIDLIST pidl)
66 LPPIDLDATA pdata =_dbg_ILGetDataPointer(pidl);
68 if (pdata)
70 switch (pdata->type)
72 case PT_MYCOMP:
73 case PT_SPECIAL:
74 return NULL;
76 case PT_DRIVE:
77 case PT_DRIVE1:
78 case PT_DRIVE2:
79 case PT_DRIVE3:
80 return (LPSTR)&(pdata->u.drive.szDriveName);
82 case PT_FOLDER:
83 case PT_FOLDER1:
84 case PT_VALUE:
85 case PT_IESPECIAL1:
86 case PT_IESPECIAL2:
87 return (LPSTR)&(pdata->u.file.szNames);
89 case PT_WORKGRP:
90 case PT_COMP:
91 case PT_NETWORK:
92 case PT_NETPROVIDER:
93 case PT_SHARE:
94 return (LPSTR)&(pdata->u.network.szNames);
97 return NULL;
100 LPSTR _dbg_ILGetSTextPointer(LPCITEMIDLIST pidl)
102 LPPIDLDATA pdata =_dbg_ILGetDataPointer(pidl);
104 if (pdata)
106 switch (pdata->type)
108 case PT_FOLDER:
109 case PT_VALUE:
110 case PT_IESPECIAL1:
111 case PT_IESPECIAL2:
112 return (LPSTR)(pdata->u.file.szNames + strlen (pdata->u.file.szNames) + 1);
114 case PT_WORKGRP:
115 return (LPSTR)(pdata->u.network.szNames + strlen (pdata->u.network.szNames) + 1);
118 return NULL;
121 REFIID _dbg_ILGetGUIDPointer(LPCITEMIDLIST pidl)
123 LPPIDLDATA pdata =_ILGetDataPointer(pidl);
125 if (pdata)
127 switch (pdata->type)
129 case PT_SPECIAL:
130 case PT_MYCOMP:
131 return (REFIID) &(pdata->u.mycomp.guid);
134 return NULL;
137 DWORD _dbg_ILSimpleGetText (LPCITEMIDLIST pidl, LPSTR szOut, UINT uOutSize)
139 DWORD dwReturn=0;
140 LPSTR szSrc;
141 GUID const * riid;
142 char szTemp[MAX_PATH];
144 if (!pidl) return 0;
146 if (szOut)
147 *szOut = 0;
149 if (_dbg_ILIsDesktop(pidl))
151 /* desktop */
152 if (szOut) strncpy(szOut, "Desktop", uOutSize);
153 dwReturn = strlen ("Desktop");
155 else if (( szSrc = _dbg_ILGetTextPointer(pidl) ))
157 /* filesystem */
158 if (szOut) strncpy(szOut, szSrc, uOutSize);
159 dwReturn = strlen(szSrc);
161 else if (( riid = _dbg_ILGetGUIDPointer(pidl) ))
163 if (szOut)
164 sprintf( szOut, "{%08lx-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x}",
165 riid->Data1, riid->Data2, riid->Data3,
166 riid->Data4[0], riid->Data4[1], riid->Data4[2], riid->Data4[3],
167 riid->Data4[4], riid->Data4[5], riid->Data4[6], riid->Data4[7] );
168 dwReturn = strlen (szTemp);
170 return dwReturn;
176 void pdump (LPCITEMIDLIST pidl)
178 LPCITEMIDLIST pidltemp = pidl;
180 if (!TRACE_ON(pidl)) return;
182 if (! pidltemp)
184 MESSAGE ("-------- pidl=NULL (Desktop)\n");
186 else
188 MESSAGE ("-------- pidl=%p\n", pidl);
189 if (pidltemp->mkid.cb)
193 DWORD dwAttrib = 0;
194 LPPIDLDATA pData = _dbg_ILGetDataPointer(pidltemp);
195 DWORD type = pData->type;
196 LPSTR szLongName = _dbg_ILGetTextPointer(pidltemp);
197 LPSTR szShortName = _dbg_ILGetSTextPointer(pidltemp);
198 char szName[MAX_PATH];
200 _dbg_ILSimpleGetText(pidltemp, szName, MAX_PATH);
201 if( PT_FOLDER == type)
202 dwAttrib = pData->u.folder.uFileAttribs;
203 else if( PT_VALUE == type)
204 dwAttrib = pData->u.file.uFileAttribs;
206 MESSAGE ("[%p] size=%04u type=%lx attr=0x%08lx name=\"%s\" (%s,%s)\n",
207 pidltemp, pidltemp->mkid.cb,type,dwAttrib,szName,debugstr_a(szLongName), debugstr_a(szShortName));
209 pidltemp = _dbg_ILGetNext(pidltemp);
211 } while (pidltemp->mkid.cb);
213 else
215 MESSAGE ("empty pidl (Desktop)\n");
217 pcheck(pidl);
220 #define BYTES_PRINTED 32
221 BOOL pcheck (LPCITEMIDLIST pidl)
223 DWORD type, ret=TRUE;
224 LPCITEMIDLIST pidltemp = pidl;
226 if (pidltemp && pidltemp->mkid.cb)
227 { do
228 { type = _dbg_ILGetDataPointer(pidltemp)->type;
229 switch (type)
230 { case PT_DESKTOP:
231 case PT_MYCOMP:
232 case PT_SPECIAL:
233 case PT_DRIVE:
234 case PT_DRIVE1:
235 case PT_DRIVE2:
236 case PT_DRIVE3:
237 case PT_FOLDER:
238 case PT_VALUE:
239 case PT_FOLDER1:
240 case PT_WORKGRP:
241 case PT_COMP:
242 case PT_NETWORK:
243 case PT_IESPECIAL1:
244 case PT_IESPECIAL2:
245 case PT_SHARE:
246 break;
247 default:
249 char szTemp[BYTES_PRINTED*4 + 1];
250 int i;
251 unsigned char c;
253 memset(szTemp, ' ', BYTES_PRINTED*4 + 1);
254 for ( i = 0; (i<pidltemp->mkid.cb) && (i<BYTES_PRINTED); i++)
256 c = ((unsigned char *)pidltemp)[i];
258 szTemp[i*3+0] = ((c>>4)>9)? (c>>4)+55 : (c>>4)+48;
259 szTemp[i*3+1] = ((0x0F&c)>9)? (0x0F&c)+55 : (0x0F&c)+48;
260 szTemp[i*3+2] = ' ';
261 szTemp[i+BYTES_PRINTED*3] = (c>=0x20 && c <=0x80) ? c : '.';
263 szTemp[BYTES_PRINTED*4] = 0x00;
264 ERR("unknown IDLIST %p [%p] size=%u type=%lx\n%s\n",pidl, pidltemp, pidltemp->mkid.cb,type, szTemp);
265 ret = FALSE;
268 pidltemp = _dbg_ILGetNext(pidltemp);
269 } while (pidltemp->mkid.cb);
271 return ret;
274 static char shdebugstr_buf1[100];
275 static char shdebugstr_buf2[100];
276 static char * shdebugstr_buf = shdebugstr_buf1;
278 static struct {
279 REFIID riid;
280 char *name;
281 } InterfaceDesc[] = {
282 {&IID_IUnknown, "IID_IUnknown"},
283 {&IID_IClassFactory, "IID_IClassFactory"},
284 {&IID_IShellView, "IID_IShellView"},
285 {&IID_IOleCommandTarget, "IID_IOleCommandTarget"},
286 {&IID_IDropTarget, "IID_IDropTarget"},
287 {&IID_IDropSource, "IID_IDropSource"},
288 {&IID_IViewObject, "IID_IViewObject"},
289 {&IID_IContextMenu, "IID_IContextMenu"},
290 {&IID_IShellExtInit, "IID_IShellExtInit"},
291 {&IID_IShellFolder, "IID_IShellFolder"},
292 {&IID_IShellFolder2, "IID_IShellFolder2"},
293 {&IID_IPersist, "IID_IPersist"},
294 {&IID_IPersistFolder, "IID_IPersistFolder"},
295 {&IID_IPersistFolder2, "IID_IPersistFolder2"},
296 {&IID_IPersistFolder3, "IID_IPersistFolder3"},
297 {&IID_IExtractIconA, "IID_IExtractIconA"},
298 {&IID_IExtractIconW, "IID_IExtractIconW"},
299 {&IID_IDataObject, "IID_IDataObject"},
300 {NULL,NULL}};
302 const char * shdebugstr_guid( const struct _GUID *id )
304 int i;
305 char* name = NULL;
306 char clsidbuf[100];
308 shdebugstr_buf = (shdebugstr_buf == shdebugstr_buf1) ? shdebugstr_buf2 : shdebugstr_buf1;
310 if (!id) {
311 strcpy (shdebugstr_buf, "(null)");
312 } else {
313 for (i=0;InterfaceDesc[i].riid && !name;i++) {
314 if (IsEqualIID(InterfaceDesc[i].riid, id)) name = InterfaceDesc[i].name;
316 if (!name) {
317 if (HCR_GetClassNameA(id, clsidbuf, 100))
318 name = clsidbuf;
321 sprintf( shdebugstr_buf, "\n\t{%08lx-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x} (%s)",
322 id->Data1, id->Data2, id->Data3,
323 id->Data4[0], id->Data4[1], id->Data4[2], id->Data4[3],
324 id->Data4[4], id->Data4[5], id->Data4[6], id->Data4[7], name ? name : "unknown" );
326 return shdebugstr_buf;