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