[BROWSEUI]
[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 _pAtlModule->Lock();
630 }
631
632 virtual ~CComDebugObject()
633 {
634 this->FinalRelease();
635 _pAtlModule->Unlock();
636 }
637
638 STDMETHOD_(ULONG, AddRef)()
639 {
640 int rc = this->InternalAddRef();
641 DbgPrint("RefCount is now %d(++)!\n", rc);
642 return rc;
643 }
644
645 STDMETHOD_(ULONG, Release)()
646 {
647 ULONG newRefCount;
648
649 newRefCount = this->InternalRelease();
650 DbgPrint("RefCount is now %d(--)!\n", newRefCount);
651 if (newRefCount == 0)
652 delete this;
653 return newRefCount;
654 }
655
656 STDMETHOD(QueryInterface)(REFIID iid, void **ppvObject)
657 {
658 return this->_InternalQueryInterface(iid, ppvObject);
659 }
660
661 static HRESULT WINAPI CreateInstance(CComDebugObject<Base> **pp)
662 {
663 CComDebugObject<Base> *newInstance;
664 HRESULT hResult;
665
666 ATLASSERT(pp != NULL);
667 if (pp == NULL)
668 return E_POINTER;
669
670 hResult = E_OUTOFMEMORY;
671 newInstance = NULL;
672 ATLTRY(newInstance = new CComDebugObject<Base>())
673 if (newInstance != NULL)
674 {
675 newInstance->SetVoid(NULL);
676 newInstance->InternalFinalConstructAddRef();
677 hResult = newInstance->_AtlInitialConstruct();
678 if (SUCCEEDED(hResult))
679 hResult = newInstance->FinalConstruct();
680 if (SUCCEEDED(hResult))
681 hResult = newInstance->_AtlFinalConstruct();
682 newInstance->InternalFinalConstructRelease();
683 if (hResult != S_OK)
684 {
685 delete newInstance;
686 newInstance = NULL;
687 }
688 }
689 *pp = newInstance;
690 return hResult;
691 }
692 };
693
694 template<class T>
695 void ReleaseCComPtrExpectZero(CComPtr<T>& cptr, BOOL forceRelease = FALSE)
696 {
697 if (cptr.p != NULL)
698 {
699 int nrc = cptr->Release();
700 if (nrc > 0)
701 {
702 DbgPrint("WARNING: Unexpected RefCount > 0 (%d)!\n", nrc);
703 if (forceRelease)
704 {
705 while (nrc > 0)
706 {
707 nrc = cptr->Release();
708 }
709 }
710 }
711 cptr.Detach();
712 }
713 }
714
715 template<class T, class R>
716 HRESULT inline ShellObjectCreator(REFIID riid, R ** ppv)
717 {
718 CComPtr<T> obj;
719 HRESULT hResult;
720
721 if (ppv == NULL)
722 return E_POINTER;
723 *ppv = NULL;
724 ATLTRY(obj = new CComObject<T>);
725 if (obj.p == NULL)
726 return E_OUTOFMEMORY;
727 hResult = obj->QueryInterface(riid, reinterpret_cast<void **>(ppv));
728 if (FAILED(hResult))
729 return hResult;
730 return S_OK;
731 }
732
733 template<class T, class R>
734 HRESULT inline ShellObjectCreatorInit(REFIID riid, R ** ppv)
735 {
736 CComPtr<T> obj;
737 CComPtr<R> result;
738 HRESULT hResult;
739
740 if (ppv == NULL)
741 return E_POINTER;
742 *ppv = NULL;
743 ATLTRY(obj = new CComObject<T>);
744 if (obj.p == NULL)
745 return E_OUTOFMEMORY;
746 hResult = obj->QueryInterface(riid, reinterpret_cast<void **>(&result));
747 if (FAILED(hResult))
748 return hResult;
749
750 hResult = obj->Initialize();
751 if (FAILED(hResult))
752 return hResult;
753
754 *ppv = result.Detach();
755
756 return S_OK;
757 }
758
759 template<class T>
760 HRESULT inline ShellObjectCreatorInit(REFIID riid, void ** ppv)
761 {
762 CComPtr<T> obj;
763 CComPtr<IUnknown> result;
764 HRESULT hResult;
765
766 if (ppv == NULL)
767 return E_POINTER;
768 *ppv = NULL;
769 ATLTRY(obj = new CComObject<T>);
770 if (obj.p == NULL)
771 return E_OUTOFMEMORY;
772 hResult = obj->QueryInterface(riid, reinterpret_cast<void **>(&result));
773 if (FAILED(hResult))
774 return hResult;
775
776 hResult = obj->Initialize();
777 if (FAILED(hResult))
778 return hResult;
779
780 *ppv = result.Detach();
781
782 return S_OK;
783 }
784
785 template<class T, class T1, class R>
786 HRESULT inline ShellObjectCreatorInit(T1 initArg1, REFIID riid, R ** ppv)
787 {
788 CComPtr<T> obj;
789 CComPtr<R> result;
790 HRESULT hResult;
791
792 if (ppv == NULL)
793 return E_POINTER;
794 *ppv = NULL;
795 ATLTRY(obj = new CComObject<T>);
796 if (obj.p == NULL)
797 return E_OUTOFMEMORY;
798 hResult = obj->QueryInterface(riid, reinterpret_cast<void **>(&result));
799 if (FAILED(hResult))
800 return hResult;
801
802 hResult = obj->Initialize(initArg1);
803 if (FAILED(hResult))
804 return hResult;
805
806 *ppv = result.Detach();
807
808 return S_OK;
809 }
810
811 template<class T, class T1, class T2, class R>
812 HRESULT inline ShellObjectCreatorInit(T1 initArg1, T2 initArg2, REFIID riid, R ** ppv)
813 {
814 CComPtr<T> obj;
815 CComPtr<R> result;
816 HRESULT hResult;
817
818 if (ppv == NULL)
819 return E_POINTER;
820 *ppv = NULL;
821 ATLTRY(obj = new CComObject<T>);
822 if (obj.p == NULL)
823 return E_OUTOFMEMORY;
824 hResult = obj->QueryInterface(riid, reinterpret_cast<void **>(&result));
825 if (FAILED(hResult))
826 return hResult;
827
828 hResult = obj->Initialize(initArg1, initArg2);
829 if (FAILED(hResult))
830 return hResult;
831
832 *ppv = result.Detach();
833
834 return S_OK;
835 }
836
837 template<class T, class T1, class T2, class T3, class R>
838 HRESULT inline ShellObjectCreatorInit(T1 initArg1, T2 initArg2, T3 initArg3, REFIID riid, R ** ppv)
839 {
840 CComPtr<T> obj;
841 CComPtr<R> result;
842 HRESULT hResult;
843
844 if (ppv == NULL)
845 return E_POINTER;
846 *ppv = NULL;
847 ATLTRY(obj = new CComObject<T>);
848 if (obj.p == NULL)
849 return E_OUTOFMEMORY;
850 hResult = obj->QueryInterface(riid, reinterpret_cast<void **>(&result));
851 if (FAILED(hResult))
852 return hResult;
853
854 hResult = obj->Initialize(initArg1, initArg2, initArg3);
855 if (FAILED(hResult))
856 return hResult;
857
858 *ppv = result.Detach();
859
860 return S_OK;
861 }
862
863 template<class T, class T1, class T2, class T3, class T4, class R>
864 HRESULT inline ShellObjectCreatorInit(T1 initArg1, T2 initArg2, T3 initArg3, T4 initArg4, REFIID riid, R ** ppv)
865 {
866 CComPtr<T> obj;
867 CComPtr<R> result;
868 HRESULT hResult;
869
870 if (ppv == NULL)
871 return E_POINTER;
872 *ppv = NULL;
873 ATLTRY(obj = new CComObject<T>);
874 if (obj.p == NULL)
875 return E_OUTOFMEMORY;
876 hResult = obj->QueryInterface(riid, reinterpret_cast<void **>(&result));
877 if (FAILED(hResult))
878 return hResult;
879
880 hResult = obj->Initialize(initArg1, initArg2, initArg3, initArg4);
881 if (FAILED(hResult))
882 return hResult;
883
884 *ppv = result.Detach();
885
886 return S_OK;
887 }
888 #endif /* __cplusplus */
889
890 #endif /* __WINE_UNDOCSHELL_H */