* Sync up to trunk head (r64377).
[reactos.git] / base / shell / rshell / precomp.h
1
2 #ifdef _MSC_VER
3
4 // Disabling spammy warnings when compiling with /W4 or /Wall
5 #pragma warning(disable:4100) // unreferenced formal parameter
6 #pragma warning(disable:4201) // nonstandard extension used
7 #pragma warning(disable:4265) // class has virtual functions, but destructor is not virtual
8 #pragma warning(disable:4365) // signed/unsigned mismatch
9 #pragma warning(disable:4514) // unreferenced inline function
10 #pragma warning(disable:4710) // function was not inlined
11 #pragma warning(disable:4820) // padding added
12 #pragma warning(disable:4946) // reinterpret_cast between related classes
13
14 // Disable some warnings in headers only
15 #pragma warning(push)
16 #pragma warning(disable:4244) // possible loss of data
17 #pragma warning(disable:4512) // assignment operator could not be gernerated
18 #endif
19
20 #define USE_SYSTEM_MENUDESKBAR 0
21 #define USE_SYSTEM_MENUSITE 0
22 #define USE_SYSTEM_MENUBAND 0
23
24 #define WRAP_MENUDESKBAR 0
25 #define WRAP_MENUSITE 0
26 #define WRAP_MENUBAND 0
27 #define WRAP_TRAYPRIV 0
28
29 #define MERGE_FOLDERS 1
30
31 #include <stdio.h>
32 #include <tchar.h>
33
34 #define WIN32_NO_STATUS
35 #define _INC_WINDOWS
36 #define COM_NO_WINDOWS_H
37
38 #define COBJMACROS
39
40 #include <windef.h>
41 #include <winbase.h>
42 #include <winreg.h>
43 #include <wingdi.h>
44 #include <winnls.h>
45 #include <wincon.h>
46 #include <shellapi.h>
47 #include <shlobj.h>
48 #include <shlobj_undoc.h>
49 #include <shlwapi.h>
50 #include <shlguid_undoc.h>
51 #include <uxtheme.h>
52 #include <strsafe.h>
53
54 #include <atlbase.h>
55 #include <atlcom.h>
56 #include <wine/debug.h>
57
58 #if _MSC_VER
59 // Restore warnings
60 #pragma warning(pop)
61 #endif
62
63 #define shell32_hInstance 0
64 #define SMC_EXEC 4
65 extern "C" INT WINAPI Shell_GetCachedImageIndex(LPCWSTR szPath, INT nIndex, UINT bSimulateDoc);
66
67 extern "C" HRESULT WINAPI CStartMenu_Constructor(REFIID riid, void **ppv);
68 extern "C" HRESULT WINAPI CMenuDeskBar_Constructor(REFIID riid, LPVOID *ppv);
69 extern "C" HRESULT WINAPI CMenuSite_Constructor(REFIID riid, LPVOID *ppv);
70 extern "C" HRESULT WINAPI CMenuBand_Constructor(REFIID riid, LPVOID *ppv);
71 extern "C" HRESULT WINAPI CMenuDeskBar_Wrapper(IDeskBar * db, REFIID riid, LPVOID *ppv);
72 extern "C" HRESULT WINAPI CMenuSite_Wrapper(IBandSite * bs, REFIID riid, LPVOID *ppv);
73 extern "C" HRESULT WINAPI CMenuBand_Wrapper(IShellMenu * sm, REFIID riid, LPVOID *ppv);
74 extern "C" HRESULT WINAPI CMergedFolder_Constructor(REFIID riid, LPVOID *ppv);
75 extern "C" HRESULT WINAPI CStartMenuSite_Wrapper(ITrayPriv * trayPriv, REFIID riid, LPVOID *ppv);
76
77 static __inline ULONG
78 Win32DbgPrint(const char *filename, int line, const char *lpFormat, ...)
79 {
80 char szMsg[512];
81 char *szMsgStart;
82 const char *fname;
83 va_list vl;
84 ULONG uRet;
85
86 fname = strrchr(filename, '\\');
87 if (fname == NULL)
88 {
89 fname = strrchr(filename, '/');
90 }
91
92 if (fname == NULL)
93 fname = filename;
94 else
95 fname++;
96
97 szMsgStart = szMsg + sprintf(szMsg, "[%10lu] %s:%d: ", GetTickCount(), fname, line);
98
99 va_start(vl, lpFormat);
100 uRet = (ULONG) vsprintf(szMsgStart, lpFormat, vl);
101 va_end(vl);
102
103 OutputDebugStringA(szMsg);
104
105 return uRet;
106 }
107
108 #define DbgPrint(fmt, ...) \
109 Win32DbgPrint(__FILE__, __LINE__, fmt, ##__VA_ARGS__)
110
111 #if 1
112 #define FAILED_UNEXPECTEDLY(hr) (FAILED(hr) && (DbgPrint("Unexpected failure %08x.\n", hr), TRUE))
113 #else
114 #define FAILED_UNEXPECTEDLY(hr) FAILED(hr)
115 #endif
116
117
118 template <class Base>
119 class CComDebugObject : public Base
120 {
121 public:
122 CComDebugObject(void * = NULL)
123 {
124 _pAtlModule->Lock();
125 }
126
127 virtual ~CComDebugObject()
128 {
129 this->FinalRelease();
130 _pAtlModule->Unlock();
131 }
132
133 STDMETHOD_(ULONG, AddRef)()
134 {
135 int rc = this->InternalAddRef();
136 DbgPrint("RefCount is now %d(++)!\n", rc);
137 return rc;
138 }
139
140 STDMETHOD_(ULONG, Release)()
141 {
142 ULONG newRefCount;
143
144 newRefCount = this->InternalRelease();
145 DbgPrint("RefCount is now %d(--)!\n", newRefCount);
146 if (newRefCount == 0)
147 delete this;
148 return newRefCount;
149 }
150
151 STDMETHOD(QueryInterface)(REFIID iid, void **ppvObject)
152 {
153 return this->_InternalQueryInterface(iid, ppvObject);
154 }
155
156 static HRESULT WINAPI CreateInstance(CComDebugObject<Base> **pp)
157 {
158 CComDebugObject<Base> *newInstance;
159 HRESULT hResult;
160
161 ATLASSERT(pp != NULL);
162 if (pp == NULL)
163 return E_POINTER;
164
165 hResult = E_OUTOFMEMORY;
166 newInstance = NULL;
167 ATLTRY(newInstance = new CComDebugObject<Base>())
168 if (newInstance != NULL)
169 {
170 newInstance->SetVoid(NULL);
171 newInstance->InternalFinalConstructAddRef();
172 hResult = newInstance->_AtlInitialConstruct();
173 if (SUCCEEDED(hResult))
174 hResult = newInstance->FinalConstruct();
175 if (SUCCEEDED(hResult))
176 hResult = newInstance->_AtlFinalConstruct();
177 newInstance->InternalFinalConstructRelease();
178 if (hResult != S_OK)
179 {
180 delete newInstance;
181 newInstance = NULL;
182 }
183 }
184 *pp = newInstance;
185 return hResult;
186 }
187 };