[RSHELL]
[reactos.git] / include / reactos / undocshell.h
1 /*
2 * Copyright 1999, 2000 Juergen Schmied
3 *
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.
8 *
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.
13 *
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
17 */
18
19 #ifndef __WINE_UNDOCSHELL_H
20 #define __WINE_UNDOCSHELL_H
21
22 #ifdef __cplusplus
23 extern "C" {
24 #endif /* defined(__cplusplus) */
25
26 /****************************************************************************
27 * IDList Functions
28 */
29 BOOL WINAPI ILGetDisplayName(
30 LPCITEMIDLIST pidl,
31 LPVOID path);
32
33 /* type parameter for ILGetDisplayNameEx() */
34 #define ILGDN_FORPARSING 0
35 #define ILGDN_NORMAL 1
36 #define ILGDN_INFOLDER 2
37
38 BOOL WINAPI ILGetDisplayNameEx(
39 LPSHELLFOLDER psf,
40 LPCITEMIDLIST pidl,
41 LPVOID path,
42 DWORD type);
43
44 LPITEMIDLIST WINAPI ILGlobalClone(LPCITEMIDLIST pidl);
45 void WINAPI ILGlobalFree(LPITEMIDLIST pidl);
46 LPITEMIDLIST WINAPI SHSimpleIDListFromPathA (LPCSTR lpszPath); //FIXME
47 LPITEMIDLIST WINAPI SHSimpleIDListFromPathW (LPCWSTR lpszPath);
48
49 HRESULT WINAPI SHILCreateFromPathA (
50 LPCSTR path,
51 LPITEMIDLIST * ppidl,
52 DWORD *attributes);
53
54 HRESULT WINAPI SHILCreateFromPathW (
55 LPCWSTR path,
56 LPITEMIDLIST * ppidl,
57 DWORD *attributes);
58
59 /*
60 string functions
61 */
62 BOOL WINAPI StrRetToStrNA(LPSTR,DWORD,LPSTRRET,const ITEMIDLIST*);
63 BOOL WINAPI StrRetToStrNW(LPWSTR,DWORD,LPSTRRET,const ITEMIDLIST*);
64
65
66 /****************************************************************************
67 * SHChangeNotifyRegister API
68 */
69 #define SHCNRF_InterruptLevel 0x0001
70 #define SHCNRF_ShellLevel 0x0002
71 #define SHCNRF_RecursiveInterrupt 0x1000 /* Must be combined with SHCNRF_InterruptLevel */
72 #define SHCNRF_NewDelivery 0x8000 /* Messages use shared memory */
73
74
75 /****************************************************************************
76 * Shell Common Dialogs
77 */
78
79 /* RunFileDlg flags */
80 #define RFF_NOBROWSE 0x01
81 #define RFF_NODEFAULT 0x02
82 #define RFF_CALCDIRECTORY 0x04
83 #define RFF_NOLABEL 0x08
84 #define RFF_NOSEPARATEMEM 0x20 /* NT only */
85
86 #define DE_SAMEFILE 0x71
87
88 /* RunFileFlg notification structure */
89 typedef struct
90 {
91 NMHDR hdr;
92 LPCSTR lpFile;
93 LPCSTR lpDirectory;
94 int nShow;
95 } NM_RUNFILEDLG, * LPNM_RUNFILEDLG;
96
97 /* RunFileDlg notification return values */
98 #define RF_OK 0x00
99 #define RF_CANCEL 0x01
100 #define RF_RETRY 0x02
101
102 void WINAPI RunFileDlg(
103 HWND hwndOwner,
104 HICON hIcon,
105 LPCWSTR lpstrDirectory,
106 LPCWSTR lpstrTitle,
107 LPCWSTR lpstrDescription,
108 UINT uFlags);
109
110 void WINAPI ExitWindowsDialog(HWND hwndOwner);
111
112 BOOL WINAPI SHFindComputer(
113 LPCITEMIDLIST pidlRoot,
114 LPCITEMIDLIST pidlSavedSearch);
115
116 void WINAPI SHHandleDiskFull(HWND hwndOwner,
117 UINT uDrive);
118
119 int WINAPI SHOutOfMemoryMessageBox(
120 HWND hwndOwner,
121 LPCSTR lpCaption,
122 UINT uType);
123
124 DWORD WINAPI SHNetConnectionDialog(
125 HWND hwndOwner,
126 LPCWSTR lpstrRemoteName,
127 DWORD dwType);
128
129 /****************************************************************************
130 * Cabinet Window Messages
131 */
132
133 #define CWM_SETPATH (WM_USER + 2)
134 #define CWM_WANTIDLE (WM_USER + 3)
135 #define CWM_GETSETCURRENTINFO (WM_USER + 4)
136 #define CWM_SELECTITEM (WM_USER + 5)
137 #define CWM_SELECTITEMSTR (WM_USER + 6)
138 #define CWM_GETISHELLBROWSER (WM_USER + 7)
139 #define CWM_TESTPATH (WM_USER + 9)
140 #define CWM_STATECHANGE (WM_USER + 10)
141 #define CWM_GETPATH (WM_USER + 12)
142
143 /* CWM_TESTPATH types */
144 #define CWTP_ISEQUAL 0
145 #define CWTP_ISCHILD 1
146
147 /* CWM_TESTPATH structure */
148 typedef struct
149 {
150 DWORD dwType;
151 ITEMIDLIST idl;
152 } CWTESTPATHSTRUCT,* LPCWTESTPATHSTRUCT;
153
154 /****************************************************************************
155 * System Imagelist Routines
156 */
157
158 int WINAPI Shell_GetCachedImageIndexA(
159 LPCSTR lpszFileName,
160 int nIconIndex,
161 UINT bSimulateDoc);
162
163 BOOL WINAPI Shell_GetImageLists(
164 HIMAGELIST *lphimlLarge,
165 HIMAGELIST *lphimlSmall);
166
167 HICON WINAPI SHGetFileIcon(
168 DWORD dwReserved,
169 LPCSTR lpszPath,
170 DWORD dwFileAttributes,
171 UINT uFlags);
172
173 BOOL WINAPI FileIconInit(BOOL bFullInit);
174
175 /****************************************************************************
176 * File Menu Routines
177 */
178 /* FileMenu_Create nSelHeight constants */
179 #define FM_DEFAULT_SELHEIGHT -1
180 #define FM_FULL_SELHEIGHT 0
181
182 /* FileMenu_Create flags */
183 #define FMF_SMALL_ICONS 0x00
184 #define FMF_LARGE_ICONS 0x08
185 #define FMF_NO_COLUMN_BREAK 0x10
186
187 HMENU WINAPI FileMenu_Create(
188 COLORREF crBorderColor,
189 int nBorderWidth,
190 HBITMAP hBorderBmp,
191 int nSelHeight,
192 UINT uFlags);
193
194 void WINAPI FileMenu_Destroy(HMENU hMenu);
195
196 /* FileMenu_AppendItem constants */
197 #define FM_SEPARATOR (LPCSTR)1
198 #define FM_BLANK_ICON -1
199 #define FM_DEFAULT_HEIGHT 0
200
201 BOOL WINAPI FileMenu_AppendItem(
202 HMENU hMenu,
203 LPCSTR lpszText,
204 UINT uID,
205 int iIcon,
206 HMENU hMenuPopup,
207 int nItemHeight);
208
209 /* FileMenu_InsertUsingPidl flags */
210 #define FMF_NO_EMPTY_ITEM 0x01
211 #define FMF_NO_PROGRAM_GROUPS 0x04
212
213 /* FileMenu_InsertUsingPidl callback function */
214 typedef void (CALLBACK *LPFNFMCALLBACK)(LPCITEMIDLIST pidlFolder, LPCITEMIDLIST pidlFile);
215
216 int WINAPI FileMenu_InsertUsingPidl(
217 HMENU hMenu,
218 UINT uID,
219 LPCITEMIDLIST pidl,
220 UINT uFlags,
221 UINT uEnumFlags,
222 LPFNFMCALLBACK lpfnCallback);
223
224 int WINAPI FileMenu_ReplaceUsingPidl(
225 HMENU hMenu,
226 UINT uID,
227 LPCITEMIDLIST pidl,
228 UINT uEnumFlags,
229 LPFNFMCALLBACK lpfnCallback);
230
231 void WINAPI FileMenu_Invalidate(HMENU hMenu);
232
233 HMENU WINAPI FileMenu_FindSubMenuByPidl(
234 HMENU hMenu,
235 LPCITEMIDLIST pidl);
236
237 BOOL WINAPI FileMenu_TrackPopupMenuEx(
238 HMENU hMenu,
239 UINT uFlags,
240 int x,
241 int y,
242 HWND hWnd,
243 LPTPMPARAMS lptpm);
244
245 BOOL WINAPI FileMenu_GetLastSelectedItemPidls(
246 UINT uReserved,
247 LPCITEMIDLIST *ppidlFolder,
248 LPCITEMIDLIST *ppidlItem);
249
250 LRESULT WINAPI FileMenu_MeasureItem(
251 HWND hWnd,
252 LPMEASUREITEMSTRUCT lpmis);
253
254 LRESULT WINAPI FileMenu_DrawItem(
255 HWND hWnd,
256 LPDRAWITEMSTRUCT lpdis);
257
258 BOOL WINAPI FileMenu_InitMenuPopup(HMENU hMenu);
259
260 void WINAPI FileMenu_AbortInitMenu(void);
261
262 LRESULT WINAPI FileMenu_HandleMenuChar(
263 HMENU hMenu,
264 WPARAM wParam);
265
266 BOOL WINAPI FileMenu_DeleteAllItems(HMENU hMenu);
267
268 BOOL WINAPI FileMenu_DeleteItemByCmd(
269 HMENU hMenu,
270 UINT uID);
271
272 BOOL WINAPI FileMenu_DeleteItemByIndex(
273 HMENU hMenu,
274 UINT uPos);
275
276 BOOL WINAPI FileMenu_DeleteMenuItemByFirstID(
277 HMENU hMenu,
278 UINT uID);
279
280 BOOL WINAPI FileMenu_DeleteSeparator(HMENU hMenu);
281
282 BOOL WINAPI FileMenu_EnableItemByCmd(
283 HMENU hMenu,
284 UINT uID,
285 BOOL bEnable);
286
287 DWORD WINAPI FileMenu_GetItemExtent(
288 HMENU hMenu,
289 UINT uPos);
290
291 int WINAPI FileMenu_AppendFilesForPidl(
292 HMENU hMenu,
293 LPCITEMIDLIST pidl,
294 BOOL bAddSeparator);
295
296 int WINAPI FileMenu_AddFilesForPidl(
297 HMENU hMenu,
298 UINT uReserved,
299 UINT uID,
300 LPCITEMIDLIST pidl,
301 UINT uFlags,
302 UINT uEnumFlags,
303 LPFNFMCALLBACK lpfnCallback);
304
305 /****************************************************************************
306 * Drag And Drop Routines
307 */
308
309 HRESULT WINAPI SHRegisterDragDrop(
310 HWND hWnd,
311 LPDROPTARGET lpDropTarget);
312
313 HRESULT WINAPI SHRevokeDragDrop(HWND hWnd);
314
315 BOOL WINAPI DAD_DragEnter(HWND hWnd);
316
317 BOOL WINAPI DAD_SetDragImageFromListView(
318 HWND hWnd,
319 POINT pt);
320
321 BOOL WINAPI DAD_ShowDragImage(BOOL bShow);
322
323 /****************************************************************************
324 * Path Manipulation Routines
325 */
326
327 BOOL WINAPI PathAppendAW(LPVOID lpszPath1, LPCVOID lpszPath2);
328
329 LPVOID WINAPI PathCombineAW(LPVOID szDest, LPCVOID lpszDir, LPCVOID lpszFile);
330
331 LPVOID WINAPI PathAddBackslashAW(LPVOID path);
332
333 LPVOID WINAPI PathBuildRootAW(LPVOID lpszPath, int drive);
334
335 LPVOID WINAPI PathFindExtensionAW(LPCVOID path);
336
337 LPVOID WINAPI PathFindFileNameAW(LPCVOID path);
338
339 LPVOID WINAPI PathGetExtensionAW(LPCVOID lpszPath, DWORD void1, DWORD void2);
340
341 LPVOID WINAPI PathGetArgsAW(LPVOID lpszPath);
342
343 BOOL WINAPI PathRemoveFileSpecAW(LPVOID lpszPath);
344
345 void WINAPI PathRemoveBlanksAW(LPVOID lpszPath);
346
347 VOID WINAPI PathQuoteSpacesAW(LPVOID path);
348
349 void WINAPI PathUnquoteSpacesAW(LPVOID lpszPath);
350
351 BOOL WINAPI PathIsUNCAW(LPCVOID lpszPath);
352
353 BOOL WINAPI PathIsRelativeAW(LPCVOID lpszPath);
354
355 BOOL WINAPI PathIsRootAW(LPCVOID x);
356
357 BOOL WINAPI PathIsExeAW(LPCVOID lpszPath);
358
359 BOOL WINAPI PathIsDirectoryAW(LPCVOID lpszPath);
360
361 BOOL WINAPI PathFileExistsAW(LPCVOID lpszPath);
362
363 BOOL WINAPI PathMatchSpecAW(LPVOID lpszPath, LPVOID lpszSpec);
364
365 BOOL WINAPI PathMakeUniqueNameAW(
366 LPVOID lpszBuffer,
367 DWORD dwBuffSize,
368 LPCVOID lpszShortName,
369 LPCVOID lpszLongName,
370 LPCVOID lpszPathName);
371
372 BOOL WINAPI PathYetAnotherMakeUniqueName(
373 LPWSTR lpszBuffer,
374 LPCWSTR lpszPathName,
375 LPCWSTR lpszShortName,
376 LPCWSTR lpszLongName);
377
378 BOOL WINAPI PathQualifyAW(LPCVOID path);
379
380
381 /* PathResolve flags */
382 #define PRF_CHECKEXISTANCE 0x01
383 #define PRF_EXECUTABLE 0x02
384 #define PRF_QUALIFYONPATH 0x04
385 #define PRF_WINDOWS31 0x08
386
387 BOOL WINAPI PathResolveAW(LPVOID lpszPath, LPCVOID *alpszPaths, DWORD dwFlags);
388
389 VOID WINAPI PathSetDlgItemPathAW(HWND hDlg, int nIDDlgItem, LPCVOID lpszPath);
390
391 /* PathProcessCommand flags */
392 #define PPCF_QUOTEPATH 0x01 /* implies PPCF_INCLUDEARGS */
393 #define PPCF_INCLUDEARGS 0x02
394 //#define PPCF_NODIRECTORIES 0x10 move to shlobj
395 #define PPCF_DONTRESOLVE 0x20
396 #define PPCF_PATHISRELATIVE 0x40
397
398 HRESULT WINAPI PathProcessCommandAW(LPCVOID lpszPath, LPVOID lpszBuff,
399 DWORD dwBuffSize, DWORD dwFlags);
400
401 void WINAPI PathStripPathAW(LPVOID lpszPath);
402
403 BOOL WINAPI PathStripToRootAW(LPVOID lpszPath);
404
405 void WINAPI PathRemoveArgsAW(LPVOID lpszPath);
406
407 void WINAPI PathRemoveExtensionAW(LPVOID lpszPath);
408
409 int WINAPI PathParseIconLocationAW(LPVOID lpszPath);
410
411 BOOL WINAPI PathIsSameRootAW(LPCVOID lpszPath1, LPCVOID lpszPath2);
412
413 BOOL WINAPI PathFindOnPathAW(LPVOID sFile, LPCVOID *sOtherDirs);
414
415 /****************************************************************************
416 * Shell Namespace Routines
417 */
418
419 /* Generic structure used by several messages */
420 typedef struct
421 {
422 DWORD dwReserved;
423 DWORD dwReserved2;
424 LPCITEMIDLIST pidl;
425 LPDWORD lpdwUser;
426 } SFVCBINFO, * LPSFVCBINFO;
427 typedef const SFVCBINFO * LPCSFVCBINFO;
428
429 /* SFVCB_SELECTIONCHANGED structure */
430 typedef struct
431 {
432 UINT uOldState;
433 UINT uNewState;
434 LPCITEMIDLIST pidl;
435 LPDWORD lpdwUser;
436 } SFVSELECTSTATE, * LPSFVSELECTSTATE;
437 typedef const SFVSELECTSTATE * LPCSFVSELECTSTATE;
438
439 /* SFVCB_COPYHOOKCALLBACK structure */
440 typedef struct
441 {
442 HWND hwnd;
443 UINT wFunc;
444 UINT wFlags;
445 LPCSTR pszSrcFile;
446 DWORD dwSrcAttribs;
447 LPCSTR pszDestFile;
448 DWORD dwDestAttribs;
449 } SFVCOPYHOOKINFO, * LPSFVCOPYHOOKINFO;
450 typedef const SFVCOPYHOOKINFO * LPCSFVCOPYHOOKINFO;
451
452 /* SFVCB_GETDETAILSOF structure */
453 typedef struct
454 {
455 LPCITEMIDLIST pidl;
456 int fmt;
457 int cx;
458 STRRET lpText;
459 } SFVCOLUMNINFO, * LPSFVCOLUMNINFO;
460
461 /****************************************************************************
462 * Misc Stuff
463 */
464
465 /* SHWaitForFileToOpen flags */
466 #define SHWFF_ADD 0x01
467 #define SHWFF_REMOVE 0x02
468 #define SHWFF_WAIT 0x04
469
470 BOOL WINAPI SHWaitForFileToOpen(
471 LPCITEMIDLIST pidl,
472 DWORD dwFlags,
473 DWORD dwTimeout);
474
475 WORD WINAPI ArrangeWindows(
476 HWND hwndParent,
477 DWORD dwReserved,
478 LPCRECT lpRect,
479 WORD cKids,
480 CONST HWND * lpKids);
481
482 /* RegisterShellHook types */
483 #define RSH_DEREGISTER 0
484 #define RSH_REGISTER 1
485 #define RSH_REGISTER_PROGMAN 2
486 #define RSH_REGISTER_TASKMAN 3
487
488 BOOL WINAPI RegisterShellHook(
489 HWND hWnd,
490 DWORD dwType);
491
492 /* SHCreateDefClassObject callback function */
493 typedef HRESULT (CALLBACK *LPFNCDCOCALLBACK)(
494 LPUNKNOWN pUnkOuter,
495 REFIID riidObject,
496 LPVOID *ppvObject);
497
498 HRESULT WINAPI SHCreateDefClassObject(
499 REFIID riidFactory,
500 LPVOID *ppvFactory,
501 LPFNCDCOCALLBACK lpfnCallback,
502 LPDWORD lpdwUsage,
503 REFIID riidObject);
504
505 void WINAPI SHFreeUnusedLibraries(void);
506
507 /* SHCreateLinks flags */
508 #define SHCLF_PREFIXNAME 0x01
509 #define SHCLF_CREATEONDESKTOP 0x02
510
511 HRESULT WINAPI SHCreateLinks(
512 HWND hWnd,
513 LPCSTR lpszDir,
514 LPDATAOBJECT lpDataObject,
515 UINT uFlags,
516 LPITEMIDLIST *lppidlLinks);
517
518 DWORD WINAPI CheckEscapesA(LPSTR string, DWORD len);
519 DWORD WINAPI CheckEscapesW(LPWSTR string, DWORD len);
520
521 /* policy functions */
522 BOOL WINAPI SHInitRestricted(LPCVOID unused, LPCVOID inpRegKey);
523
524 /* Shell Desktop functions */
525
526 #define WM_GETISHELLBROWSER (WM_USER+7)
527
528 BOOL WINAPI SHDesktopMessageLoop(HANDLE);
529
530 #define CSIDL_FOLDER_MASK 0x00ff
531
532 /* Utility functions */
533 #include <stdio.h>
534
535 static inline ULONG
536 Win32DbgPrint(const char *filename, int line, const char *lpFormat, ...)
537 {
538 char szMsg[512];
539 char *szMsgStart;
540 const char *fname;
541 va_list vl;
542 ULONG uRet;
543
544 fname = strrchr(filename, '\\');
545 if (fname == NULL)
546 {
547 fname = strrchr(filename, '/');
548 if (fname != NULL)
549 fname++;
550 }
551 else
552 fname++;
553
554 if (fname == NULL)
555 fname = filename;
556
557 szMsgStart = szMsg + sprintf(szMsg, "%s:%d: ", fname, line);
558
559 va_start(vl, lpFormat);
560 uRet = (ULONG) vsprintf(szMsgStart, lpFormat, vl);
561 va_end(vl);
562
563 OutputDebugStringA(szMsg);
564
565 return uRet;
566 }
567
568 #define DbgPrint(fmt, ...) \
569 Win32DbgPrint(__FILE__, __LINE__, fmt, ##__VA_ARGS__)
570
571 static inline void DbgDumpMenuInternal(HMENU hmenu, char* padding, int padlevel)
572 {
573 WCHAR label[128];
574
575 padding[padlevel] = '.';
576 padding[padlevel + 1] = '.';
577 padding[padlevel + 2] = 0;
578
579 int count = GetMenuItemCount(hmenu);
580 for (int i = 0; i < count; i++)
581 {
582 MENUITEMINFOW mii = { 0 };
583
584 mii.cbSize = sizeof(mii);
585 mii.fMask = MIIM_STRING | MIIM_FTYPE | MIIM_SUBMENU | MIIM_STATE | MIIM_ID;
586 mii.dwTypeData = label;
587 mii.cch = _countof(label);
588
589 GetMenuItemInfo(hmenu, i, TRUE, &mii);
590
591 if (mii.fType & MFT_BITMAP)
592 DbgPrint("%s%2d - %08x: BITMAP %08p (state=%d, has submenu=%s)\n", padding, i, mii.wID, mii.hbmpItem, mii.fState, mii.hSubMenu ? "TRUE" : "FALSE");
593 else if (mii.fType & MFT_SEPARATOR)
594 DbgPrint("%s%2d - %08x ---SEPARATOR---\n", padding, i, mii.wID);
595 else
596 DbgPrint("%s%2d - %08x: %S (state=%d, has submenu=%s)\n", padding, i, mii.wID, mii.dwTypeData, mii.fState, mii.hSubMenu ? "TRUE" : "FALSE");
597
598 if (mii.hSubMenu)
599 DbgDumpMenuInternal(mii.hSubMenu, padding, padlevel + 2);
600
601 }
602
603 padding[padlevel] = 0;
604 }
605
606 static __inline void DbgDumpMenu(HMENU hmenu)
607 {
608 char padding[128];
609 DbgDumpMenuInternal(hmenu, padding, 0);
610 }
611
612 #if 1
613 #define FAILED_UNEXPECTEDLY(hr) (FAILED(hr) && (DbgPrint("Unexpected failure %08x.\n", hr), TRUE))
614 #else
615 #define FAILED_UNEXPECTEDLY(hr) FAILED(hr)
616 #endif
617
618 #ifdef __cplusplus
619 } /* extern "C" */
620 #endif /* defined(__cplusplus) */
621
622 #ifdef __cplusplus
623 template <class Base>
624 class CComDebugObject : public Base
625 {
626 public:
627 CComDebugObject(void * = NULL)
628 {
629 #if DEBUG_CCOMOBJECT_CREATION
630 DbgPrint("%S, this=%08p\n", __FUNCTION__, static_cast<Base*>(this));
631 #endif
632 _pAtlModule->Lock();
633 }
634
635 virtual ~CComDebugObject()
636 {
637 this->FinalRelease();
638 _pAtlModule->Unlock();
639 }
640
641 STDMETHOD_(ULONG, AddRef)()
642 {
643 int rc = this->InternalAddRef();
644 #if DEBUG_CCOMOBJECT_REFCOUNTING
645 DbgPrint("%s, RefCount is now %d(--)! \n", __FUNCTION__, rc);
646 #endif
647 return rc;
648 }
649
650 STDMETHOD_(ULONG, Release)()
651 {
652 int rc = this->InternalRelease();
653
654 #if DEBUG_CCOMOBJECT_REFCOUNTING
655 DbgPrint("%s, RefCount is now %d(--)! \n", __FUNCTION__, rc);
656 #endif
657
658 if (rc == 0)
659 {
660 #if DEBUG_CCOMOBJECT_DESTRUCTION
661 DbgPrint("%s, RefCount reached 0 Deleting!\n", __FUNCTION__);
662 #endif
663 delete this;
664 }
665 return rc;
666 }
667
668 STDMETHOD(QueryInterface)(REFIID iid, void **ppvObject)
669 {
670 return this->_InternalQueryInterface(iid, ppvObject);
671 }
672
673 static HRESULT WINAPI CreateInstance(CComDebugObject<Base> **pp)
674 {
675 CComDebugObject<Base> *newInstance;
676 HRESULT hResult;
677
678 ATLASSERT(pp != NULL);
679 if (pp == NULL)
680 return E_POINTER;
681
682 hResult = E_OUTOFMEMORY;
683 newInstance = NULL;
684 ATLTRY(newInstance = new CComDebugObject<Base>());
685 if (newInstance != NULL)
686 {
687 newInstance->SetVoid(NULL);
688 newInstance->InternalFinalConstructAddRef();
689 hResult = newInstance->_AtlInitialConstruct();
690 if (SUCCEEDED(hResult))
691 hResult = newInstance->FinalConstruct();
692 if (SUCCEEDED(hResult))
693 hResult = newInstance->_AtlFinalConstruct();
694 newInstance->InternalFinalConstructRelease();
695 if (hResult != S_OK)
696 {
697 delete newInstance;
698 newInstance = NULL;
699 }
700 }
701 *pp = newInstance;
702 return hResult;
703 }
704 };
705
706 #ifdef DEBUG_CCOMOBJECT
707 # define _CComObject CComDebugObject
708 #else
709 # define _CComObject CComObject
710 #endif
711
712 template<class T>
713 void ReleaseCComPtrExpectZero(CComPtr<T>& cptr, BOOL forceRelease = FALSE)
714 {
715 if (cptr.p != NULL)
716 {
717 int nrc = cptr->Release();
718 if (nrc > 0)
719 {
720 DbgPrint("WARNING: Unexpected RefCount > 0 (%d)!\n", nrc);
721 if (forceRelease)
722 {
723 while (nrc > 0)
724 {
725 nrc = cptr->Release();
726 }
727 }
728 }
729 cptr.Detach();
730 }
731 }
732
733 template<class T, class R>
734 HRESULT inline ShellDebugObjectCreator(REFIID riid, R ** ppv)
735 {
736 CComPtr<T> obj;
737 HRESULT hResult;
738
739 if (ppv == NULL)
740 return E_POINTER;
741 *ppv = NULL;
742 ATLTRY(obj = new CComDebugObject<T>);
743 if (obj.p == NULL)
744 return E_OUTOFMEMORY;
745 hResult = obj->QueryInterface(riid, reinterpret_cast<void **>(ppv));
746 if (FAILED(hResult))
747 return hResult;
748 return S_OK;
749 }
750
751 template<class T, class R>
752 HRESULT inline ShellObjectCreator(REFIID riid, R ** ppv)
753 {
754 CComPtr<T> obj;
755 HRESULT hResult;
756
757 if (ppv == NULL)
758 return E_POINTER;
759 *ppv = NULL;
760 ATLTRY(obj = new _CComObject<T>);
761 if (obj.p == NULL)
762 return E_OUTOFMEMORY;
763 hResult = obj->QueryInterface(riid, reinterpret_cast<void **>(ppv));
764 if (FAILED(hResult))
765 return hResult;
766 return S_OK;
767 }
768
769 template<class T, class R>
770 HRESULT inline ShellObjectCreatorInit(REFIID riid, R ** ppv)
771 {
772 CComPtr<T> obj;
773 CComPtr<R> result;
774 HRESULT hResult;
775
776 if (ppv == NULL)
777 return E_POINTER;
778 *ppv = NULL;
779 ATLTRY(obj = new _CComObject<T>);
780 if (obj.p == NULL)
781 return E_OUTOFMEMORY;
782 hResult = obj->QueryInterface(riid, reinterpret_cast<void **>(&result));
783 if (FAILED(hResult))
784 return hResult;
785
786 hResult = obj->Initialize();
787 if (FAILED(hResult))
788 return hResult;
789
790 *ppv = result.Detach();
791
792 return S_OK;
793 }
794
795 template<class T>
796 HRESULT inline ShellObjectCreatorInit(REFIID riid, void ** ppv)
797 {
798 CComPtr<T> obj;
799 CComPtr<IUnknown> result;
800 HRESULT hResult;
801
802 if (ppv == NULL)
803 return E_POINTER;
804 *ppv = NULL;
805 ATLTRY(obj = new _CComObject<T>);
806 if (obj.p == NULL)
807 return E_OUTOFMEMORY;
808 hResult = obj->QueryInterface(riid, reinterpret_cast<void **>(&result));
809 if (FAILED(hResult))
810 return hResult;
811
812 hResult = obj->Initialize();
813 if (FAILED(hResult))
814 return hResult;
815
816 *ppv = result.Detach();
817
818 return S_OK;
819 }
820
821 template<class T, class T1, class R>
822 HRESULT inline ShellObjectCreatorInit(T1 initArg1, REFIID riid, R ** ppv)
823 {
824 CComPtr<T> obj;
825 CComPtr<R> result;
826 HRESULT hResult;
827
828 if (ppv == NULL)
829 return E_POINTER;
830 *ppv = NULL;
831 ATLTRY(obj = new _CComObject<T>);
832 if (obj.p == NULL)
833 return E_OUTOFMEMORY;
834 hResult = obj->QueryInterface(riid, reinterpret_cast<void **>(&result));
835 if (FAILED(hResult))
836 return hResult;
837
838 hResult = obj->Initialize(initArg1);
839 if (FAILED(hResult))
840 return hResult;
841
842 *ppv = result.Detach();
843
844 return S_OK;
845 }
846
847 template<class T, class T1, class T2, class R>
848 HRESULT inline ShellObjectCreatorInit(T1 initArg1, T2 initArg2, REFIID riid, R ** ppv)
849 {
850 CComPtr<T> obj;
851 CComPtr<R> result;
852 HRESULT hResult;
853
854 if (ppv == NULL)
855 return E_POINTER;
856 *ppv = NULL;
857 ATLTRY(obj = new _CComObject<T>);
858 if (obj.p == NULL)
859 return E_OUTOFMEMORY;
860 hResult = obj->QueryInterface(riid, reinterpret_cast<void **>(&result));
861 if (FAILED(hResult))
862 return hResult;
863
864 hResult = obj->Initialize(initArg1, initArg2);
865 if (FAILED(hResult))
866 return hResult;
867
868 *ppv = result.Detach();
869
870 return S_OK;
871 }
872
873 template<class T, class T1, class T2, class T3, class R>
874 HRESULT inline ShellObjectCreatorInit(T1 initArg1, T2 initArg2, T3 initArg3, REFIID riid, R ** ppv)
875 {
876 CComPtr<T> obj;
877 CComPtr<R> result;
878 HRESULT hResult;
879
880 if (ppv == NULL)
881 return E_POINTER;
882 *ppv = NULL;
883 ATLTRY(obj = new _CComObject<T>);
884 if (obj.p == NULL)
885 return E_OUTOFMEMORY;
886 hResult = obj->QueryInterface(riid, reinterpret_cast<void **>(&result));
887 if (FAILED(hResult))
888 return hResult;
889
890 hResult = obj->Initialize(initArg1, initArg2, initArg3);
891 if (FAILED(hResult))
892 return hResult;
893
894 *ppv = result.Detach();
895
896 return S_OK;
897 }
898
899 template<class T, class T1, class T2, class T3, class T4, class R>
900 HRESULT inline ShellObjectCreatorInit(T1 initArg1, T2 initArg2, T3 initArg3, T4 initArg4, REFIID riid, R ** ppv)
901 {
902 CComPtr<T> obj;
903 CComPtr<R> result;
904 HRESULT hResult;
905
906 if (ppv == NULL)
907 return E_POINTER;
908 *ppv = NULL;
909 ATLTRY(obj = new _CComObject<T>);
910 if (obj.p == NULL)
911 return E_OUTOFMEMORY;
912 hResult = obj->QueryInterface(riid, reinterpret_cast<void **>(&result));
913 if (FAILED(hResult))
914 return hResult;
915
916 hResult = obj->Initialize(initArg1, initArg2, initArg3, initArg4);
917 if (FAILED(hResult))
918 return hResult;
919
920 *ppv = result.Detach();
921
922 return S_OK;
923 }
924 #endif /* __cplusplus */
925
926 #endif /* __WINE_UNDOCSHELL_H */