A Fast Bresenham Type Algorithm For Drawing Ellipses by John Kennedy
[xy_vsfilter.git] / src / apps / mplayerc / FakeFilterMapper2.cpp
blob216c9b2d508973e888a684b6a4f7c96c4dd97a27
1 /*
2 * Copyright (C) 2003-2006 Gabest
3 * http://www.gabest.org
5 * This Program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2, or (at your option)
8 * any later version.
9 *
10 * This Program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with GNU Make; see the file COPYING. If not, write to
17 * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
18 * http://www.gnu.org/copyleft/gpl.html
22 #include "stdafx.h"
23 #include "fakefiltermapper2.h"
24 #include "MacrovisionKicker.h"
25 #include "..\..\..\include\detours\detours.h"
26 #include "..\..\DSUtil\DSUtil.h"
28 #include <initguid.h>
29 #include <qedit.h>
31 DETOUR_TRAMPOLINE(HRESULT WINAPI Real_CoCreateInstance(IN REFCLSID rclsid, IN LPUNKNOWN pUnkOuter, IN DWORD dwClsContext, IN REFIID riid, OUT LPVOID FAR* ppv), CoCreateInstance);
32 DETOUR_TRAMPOLINE(LONG WINAPI Real_RegCloseKey(HKEY a0), RegCloseKey);
33 DETOUR_TRAMPOLINE(LONG WINAPI Real_RegFlushKey(HKEY a0), RegFlushKey);
34 DETOUR_TRAMPOLINE(LONG WINAPI Real_RegCreateKeyA(HKEY a0, LPCSTR a1, PHKEY a2), RegCreateKeyA);
35 DETOUR_TRAMPOLINE(LONG WINAPI Real_RegCreateKeyW(HKEY a0, LPCWSTR a1, PHKEY a2), RegCreateKeyW);
36 DETOUR_TRAMPOLINE(LONG WINAPI Real_RegCreateKeyExA(HKEY a0, LPCSTR a1, DWORD a2, LPSTR a3, DWORD a4, REGSAM a5, LPSECURITY_ATTRIBUTES a6, PHKEY a7, LPDWORD a8), RegCreateKeyExA);
37 DETOUR_TRAMPOLINE(LONG WINAPI Real_RegCreateKeyExW(HKEY a0, LPCWSTR a1, DWORD a2, LPWSTR a3, DWORD a4, REGSAM a5, LPSECURITY_ATTRIBUTES a6, PHKEY a7, LPDWORD a8), RegCreateKeyExW);
38 DETOUR_TRAMPOLINE(LONG WINAPI Real_RegDeleteKeyA(HKEY a0, LPCSTR a1), RegDeleteKeyA);
39 DETOUR_TRAMPOLINE(LONG WINAPI Real_RegDeleteKeyW(HKEY a0, LPCWSTR a1), RegDeleteKeyW);
40 DETOUR_TRAMPOLINE(LONG WINAPI Real_RegDeleteValueA(HKEY a0, LPCSTR a1), RegDeleteValueA);
41 DETOUR_TRAMPOLINE(LONG WINAPI Real_RegDeleteValueW(HKEY a0, LPCWSTR a1), RegDeleteValueW);
42 DETOUR_TRAMPOLINE(LONG WINAPI Real_RegEnumKeyExA(HKEY a0, DWORD a1, LPSTR a2, LPDWORD a3, LPDWORD a4, LPSTR a5, LPDWORD a6, struct _FILETIME* a7), RegEnumKeyExA);
43 DETOUR_TRAMPOLINE(LONG WINAPI Real_RegEnumKeyExW(HKEY a0, DWORD a1, LPWSTR a2, LPDWORD a3, LPDWORD a4, LPWSTR a5, LPDWORD a6, struct _FILETIME* a7), RegEnumKeyExW);
44 DETOUR_TRAMPOLINE(LONG WINAPI Real_RegEnumValueA(HKEY a0, DWORD a1, LPSTR a2, LPDWORD a3, LPDWORD a4, LPDWORD a5, LPBYTE a6, LPDWORD a7), RegEnumValueA);
45 DETOUR_TRAMPOLINE(LONG WINAPI Real_RegEnumValueW(HKEY a0, DWORD a1, LPWSTR a2, LPDWORD a3, LPDWORD a4, LPDWORD a5, LPBYTE a6, LPDWORD a7), RegEnumValueW);
46 DETOUR_TRAMPOLINE(LONG WINAPI Real_RegOpenKeyA(HKEY a0, LPCSTR a1, PHKEY a2), RegOpenKeyA);
47 DETOUR_TRAMPOLINE(LONG WINAPI Real_RegOpenKeyW(HKEY a0, LPCWSTR a1, PHKEY a2), RegOpenKeyW);
48 DETOUR_TRAMPOLINE(LONG WINAPI Real_RegOpenKeyExA(HKEY a0, LPCSTR a1, DWORD a2, REGSAM a3, PHKEY a4), RegOpenKeyExA);
49 DETOUR_TRAMPOLINE(LONG WINAPI Real_RegOpenKeyExW(HKEY a0, LPCWSTR a1, DWORD a2, REGSAM a3, PHKEY a4), RegOpenKeyExW);
50 DETOUR_TRAMPOLINE(LONG WINAPI Real_RegQueryInfoKeyA(HKEY a0, LPSTR a1, LPDWORD a2, LPDWORD a3, LPDWORD a4, LPDWORD a5, LPDWORD a6, LPDWORD a7, LPDWORD a8, LPDWORD a9, LPDWORD a10, struct _FILETIME* a11), RegQueryInfoKeyA);
51 DETOUR_TRAMPOLINE(LONG WINAPI Real_RegQueryInfoKeyW(HKEY a0, LPWSTR a1, LPDWORD a2, LPDWORD a3, LPDWORD a4, LPDWORD a5, LPDWORD a6, LPDWORD a7, LPDWORD a8, LPDWORD a9, LPDWORD a10, struct _FILETIME* a11), RegQueryInfoKeyW);
52 DETOUR_TRAMPOLINE(LONG WINAPI Real_RegQueryValueA(HKEY a0, LPCSTR a1, LPSTR a2, PLONG a3), RegQueryValueA);
53 DETOUR_TRAMPOLINE(LONG WINAPI Real_RegQueryValueW(HKEY a0, LPCWSTR a1, LPWSTR a2, PLONG a3), RegQueryValueW);
54 DETOUR_TRAMPOLINE(LONG WINAPI Real_RegQueryValueExA(HKEY a0, LPCSTR a1, LPDWORD a2, LPDWORD a3, LPBYTE a4, LPDWORD a5), RegQueryValueExA);
55 DETOUR_TRAMPOLINE(LONG WINAPI Real_RegQueryValueExW(HKEY a0, LPCWSTR a1, LPDWORD a2, LPDWORD a3, LPBYTE a4, LPDWORD a5), RegQueryValueExW);
56 DETOUR_TRAMPOLINE(LONG WINAPI Real_RegSetValueA(HKEY a0, LPCSTR a1, DWORD a2, LPCSTR a3, DWORD a4), RegSetValueA);
57 DETOUR_TRAMPOLINE(LONG WINAPI Real_RegSetValueW(HKEY a0, LPCWSTR a1, DWORD a2, LPCWSTR a3, DWORD a4), RegSetValueW);
58 DETOUR_TRAMPOLINE(LONG WINAPI Real_RegSetValueExA(HKEY a0, LPCSTR a1, DWORD a2, DWORD a3, BYTE* a4, DWORD a5), RegSetValueExA);
59 DETOUR_TRAMPOLINE(LONG WINAPI Real_RegSetValueExW(HKEY a0, LPCWSTR a1, DWORD a2, DWORD a3, BYTE* a4, DWORD a5), RegSetValueExW);
61 HRESULT WINAPI Mine_CoCreateInstance(IN REFCLSID rclsid, IN LPUNKNOWN pUnkOuter,
62 IN DWORD dwClsContext, IN REFIID riid, OUT LPVOID FAR* ppv)
64 if(CFilterMapper2::m_pFilterMapper2)
66 CheckPointer(ppv, E_POINTER);
68 if(rclsid == CLSID_FilterMapper)
70 ASSERT(0);
71 return REGDB_E_CLASSNOTREG; // sorry...
74 if(rclsid == CLSID_FilterMapper2)
76 if(pUnkOuter) return CLASS_E_NOAGGREGATION;
78 if(riid == __uuidof(IUnknown))
80 CFilterMapper2::m_pFilterMapper2->AddRef();
81 *ppv = (IUnknown*)CFilterMapper2::m_pFilterMapper2;
82 return S_OK;
84 else if(riid == __uuidof(IFilterMapper2))
86 CFilterMapper2::m_pFilterMapper2->AddRef();
87 *ppv = (IFilterMapper2*)CFilterMapper2::m_pFilterMapper2;
88 return S_OK;
90 else
92 return E_NOINTERFACE;
96 /* else
98 if(rclsid == CLSID_FilterMapper2)
100 CFilterMapper2* pFM2 = new CFilterMapper2(true, false, pUnkOuter);
101 CComPtr<IUnknown> pUnk = (IUnknown*)pFM2;
102 return pUnk->QueryInterface(riid, ppv);
106 if(!pUnkOuter)
107 if(rclsid == CLSID_VideoMixingRenderer || rclsid == CLSID_VideoMixingRenderer9
108 || rclsid == CLSID_VideoRenderer || rclsid == CLSID_VideoRendererDefault
109 || rclsid == CLSID_OverlayMixer)// || rclsid == CLSID_OverlayMixer2 - where is this declared?)
111 CMacrovisionKicker* pMK = new CMacrovisionKicker(NAME("CMacrovisionKicker"), NULL);
112 CComPtr<IUnknown> pUnk = (IUnknown*)(INonDelegatingUnknown*)pMK;
113 CComPtr<IUnknown> pInner;
114 HRESULT hr;
115 if(SUCCEEDED(hr = Real_CoCreateInstance(rclsid, pUnk, dwClsContext, __uuidof(IUnknown), (void**)&pInner)))
117 pMK->SetInner(pInner);
118 return pUnk->QueryInterface(riid, ppv);
122 return Real_CoCreateInstance(rclsid, pUnkOuter, dwClsContext, riid, ppv);
125 #define FAKEHKEY (HKEY)0x12345678
127 LONG WINAPI Mine_RegCloseKey(HKEY a0)
129 if(CFilterMapper2::m_pFilterMapper2 && a0 == FAKEHKEY) {return ERROR_SUCCESS;}
130 return Real_RegCloseKey(a0);
132 LONG WINAPI Mine_RegFlushKey(HKEY a0)
134 if(CFilterMapper2::m_pFilterMapper2 && a0 == FAKEHKEY) {return ERROR_SUCCESS;}
135 return Real_RegFlushKey(a0);
137 LONG WINAPI Mine_RegCreateKeyA(HKEY a0, LPCSTR a1, PHKEY a2)
139 if(CFilterMapper2::m_pFilterMapper2) {*a2 = FAKEHKEY; return ERROR_SUCCESS;}
140 return Real_RegCreateKeyA(a0, a1, a2);
142 LONG WINAPI Mine_RegCreateKeyW(HKEY a0, LPCWSTR a1, PHKEY a2)
144 if(CFilterMapper2::m_pFilterMapper2) {*a2 = FAKEHKEY; return ERROR_SUCCESS;}
145 return Real_RegCreateKeyW(a0, a1, a2);
147 LONG WINAPI Mine_RegCreateKeyExA(HKEY a0, LPCSTR a1, DWORD a2, LPSTR a3, DWORD a4, REGSAM a5, LPSECURITY_ATTRIBUTES a6, PHKEY a7, LPDWORD a8)
149 if(CFilterMapper2::m_pFilterMapper2) {*a7 = FAKEHKEY; return ERROR_SUCCESS;}
150 return Real_RegCreateKeyExA(a0, a1, a2, a3, a4, a5, a6, a7, a8);
152 LONG WINAPI Mine_RegCreateKeyExW(HKEY a0, LPCWSTR a1, DWORD a2, LPWSTR a3, DWORD a4, REGSAM a5, LPSECURITY_ATTRIBUTES a6, PHKEY a7, LPDWORD a8)
154 if(CFilterMapper2::m_pFilterMapper2) {*a7 = FAKEHKEY; return ERROR_SUCCESS;}
155 return Real_RegCreateKeyExW(a0, a1, a2, a3, a4, a5, a6, a7, a8);
157 LONG WINAPI Mine_RegDeleteKeyA(HKEY a0, LPCSTR a1)
159 if(CFilterMapper2::m_pFilterMapper2 && (a0 == FAKEHKEY || (int)a0 < 0)) {return ERROR_SUCCESS;}
160 return Real_RegDeleteKeyA(a0, a1);
162 LONG WINAPI Mine_RegDeleteKeyW(HKEY a0, LPCWSTR a1)
164 if(CFilterMapper2::m_pFilterMapper2 && (a0 == FAKEHKEY || (int)a0 < 0)) {return ERROR_SUCCESS;}
165 return Real_RegDeleteKeyW(a0, a1);
167 LONG WINAPI Mine_RegDeleteValueA(HKEY a0, LPCSTR a1)
169 if(CFilterMapper2::m_pFilterMapper2 && (a0 == FAKEHKEY || (int)a0 < 0)) {return ERROR_SUCCESS;}
170 return Real_RegDeleteValueA(a0, a1);
172 LONG WINAPI Mine_RegDeleteValueW(HKEY a0, LPCWSTR a1)
174 if(CFilterMapper2::m_pFilterMapper2 && (a0 == FAKEHKEY || (int)a0 < 0)) {return ERROR_SUCCESS;}
175 return Real_RegDeleteValueW(a0, a1);
177 LONG WINAPI Mine_RegEnumKeyExA(HKEY a0, DWORD a1, LPSTR a2, LPDWORD a3, LPDWORD a4, LPSTR a5, LPDWORD a6, struct _FILETIME* a7)
179 if(CFilterMapper2::m_pFilterMapper2 && a0 == FAKEHKEY) {return ERROR_NO_MORE_ITEMS;}
180 return Real_RegEnumKeyExA(a0, a1, a2, a3, a4, a5, a6, a7);
182 LONG WINAPI Mine_RegEnumKeyExW(HKEY a0, DWORD a1, LPWSTR a2, LPDWORD a3, LPDWORD a4, LPWSTR a5, LPDWORD a6, struct _FILETIME* a7)
184 if(CFilterMapper2::m_pFilterMapper2 && a0 == FAKEHKEY) {return ERROR_NO_MORE_ITEMS;}
185 return Real_RegEnumKeyExW(a0, a1, a2, a3, a4, a5, a6, a7);
187 LONG WINAPI Mine_RegEnumValueA(HKEY a0, DWORD a1, LPSTR a2, LPDWORD a3, LPDWORD a4, LPDWORD a5, LPBYTE a6, LPDWORD a7)
189 if(CFilterMapper2::m_pFilterMapper2 && a0 == FAKEHKEY) {return ERROR_NO_MORE_ITEMS;}
190 return Real_RegEnumValueA(a0, a1, a2, a3, a4, a5, a6, a7);
192 LONG WINAPI Mine_RegEnumValueW(HKEY a0, DWORD a1, LPWSTR a2, LPDWORD a3, LPDWORD a4, LPDWORD a5, LPBYTE a6, LPDWORD a7)
194 if(CFilterMapper2::m_pFilterMapper2 && a0 == FAKEHKEY) {return ERROR_NO_MORE_ITEMS;}
195 return Real_RegEnumValueW(a0, a1, a2, a3, a4, a5, a6, a7);
197 LONG WINAPI Mine_RegOpenKeyA(HKEY a0, LPCSTR a1, PHKEY a2)
199 if(CFilterMapper2::m_pFilterMapper2) {*a2 = FAKEHKEY; return ERROR_SUCCESS;}
200 return Real_RegOpenKeyA(a0, a1, a2);
202 LONG WINAPI Mine_RegOpenKeyW(HKEY a0, LPCWSTR a1, PHKEY a2)
204 if(CFilterMapper2::m_pFilterMapper2) {*a2 = FAKEHKEY; return ERROR_SUCCESS;}
205 return Real_RegOpenKeyW(a0, a1, a2);
207 LONG WINAPI Mine_RegOpenKeyExA(HKEY a0, LPCSTR a1, DWORD a2, REGSAM a3, PHKEY a4)
209 if(CFilterMapper2::m_pFilterMapper2 && (a3&(KEY_SET_VALUE|KEY_CREATE_SUB_KEY))) {*a4 = FAKEHKEY; return ERROR_SUCCESS;}
210 return Real_RegOpenKeyExA(a0, a1, a2, a3, a4);
212 LONG WINAPI Mine_RegOpenKeyExW(HKEY a0, LPCWSTR a1, DWORD a2, REGSAM a3, PHKEY a4)
214 if(CFilterMapper2::m_pFilterMapper2 && (a3&(KEY_SET_VALUE|KEY_CREATE_SUB_KEY))) {*a4 = FAKEHKEY; return ERROR_SUCCESS;}
215 return Real_RegOpenKeyExW(a0, a1, a2, a3, a4);
217 LONG WINAPI Mine_RegQueryInfoKeyA(HKEY a0, LPSTR a1, LPDWORD a2, LPDWORD a3, LPDWORD a4, LPDWORD a5, LPDWORD a6, LPDWORD a7, LPDWORD a8, LPDWORD a9, LPDWORD a10, struct _FILETIME* a11)
219 if(CFilterMapper2::m_pFilterMapper2 && a0 == FAKEHKEY) {return ERROR_INVALID_HANDLE;}
220 return Real_RegQueryInfoKeyA(a0, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11);
222 LONG WINAPI Mine_RegQueryInfoKeyW(HKEY a0, LPWSTR a1, LPDWORD a2, LPDWORD a3, LPDWORD a4, LPDWORD a5, LPDWORD a6, LPDWORD a7, LPDWORD a8, LPDWORD a9, LPDWORD a10, struct _FILETIME* a11)
224 if(CFilterMapper2::m_pFilterMapper2 && a0 == FAKEHKEY) {return ERROR_INVALID_HANDLE;}
225 return Real_RegQueryInfoKeyW(a0, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11);
227 LONG WINAPI Mine_RegQueryValueA(HKEY a0, LPCSTR a1, LPSTR a2, PLONG a3)
229 if(CFilterMapper2::m_pFilterMapper2 && a0 == FAKEHKEY) {*a3 = 0; return ERROR_SUCCESS;}
230 return Real_RegQueryValueA(a0, a1, a2, a3);
232 LONG WINAPI Mine_RegQueryValueW(HKEY a0, LPCWSTR a1, LPWSTR a2, PLONG a3)
234 if(CFilterMapper2::m_pFilterMapper2 && a0 == FAKEHKEY) {*a3 = 0; return ERROR_SUCCESS;}
235 return Real_RegQueryValueW(a0, a1, a2, a3);
237 LONG WINAPI Mine_RegQueryValueExA(HKEY a0, LPCSTR a1, LPDWORD a2, LPDWORD a3, LPBYTE a4, LPDWORD a5)
239 if(CFilterMapper2::m_pFilterMapper2 && a0 == FAKEHKEY) {*a5 = 0; return ERROR_SUCCESS;}
240 return Real_RegQueryValueExA(a0, a1, a2, a3, a4, a5);
242 LONG WINAPI Mine_RegQueryValueExW(HKEY a0, LPCWSTR a1, LPDWORD a2, LPDWORD a3, LPBYTE a4, LPDWORD a5)
244 if(CFilterMapper2::m_pFilterMapper2 && a0 == FAKEHKEY) {*a5 = 0; return ERROR_SUCCESS;}
245 return Real_RegQueryValueExW(a0, a1, a2, a3, a4, a5);
247 LONG WINAPI Mine_RegSetValueA(HKEY a0, LPCSTR a1, DWORD a2, LPCSTR a3, DWORD a4)
249 if(CFilterMapper2::m_pFilterMapper2 && (a0 == FAKEHKEY || (int)a0 < 0)) {return ERROR_SUCCESS;}
250 return Real_RegSetValueA(a0, a1, a2, a3, a4);
252 LONG WINAPI Mine_RegSetValueW(HKEY a0, LPCWSTR a1, DWORD a2, LPCWSTR a3, DWORD a4)
254 if(CFilterMapper2::m_pFilterMapper2 && (a0 == FAKEHKEY || (int)a0 < 0)) {return ERROR_SUCCESS;}
255 return Real_RegSetValueW(a0, a1, a2, a3, a4);
257 LONG WINAPI Mine_RegSetValueExA(HKEY a0, LPCSTR a1, DWORD a2, DWORD a3, BYTE* a4, DWORD a5)
259 if(CFilterMapper2::m_pFilterMapper2 && (a0 == FAKEHKEY || (int)a0 < 0)) {return ERROR_SUCCESS;}
260 return Real_RegSetValueExA(a0, a1, a2, a3, a4, a5);
262 LONG WINAPI Mine_RegSetValueExW(HKEY a0, LPCWSTR a1, DWORD a2, DWORD a3, BYTE* a4, DWORD a5)
264 if(CFilterMapper2::m_pFilterMapper2 && (a0 == FAKEHKEY || (int)a0 < 0)) {return ERROR_SUCCESS;}
265 return Real_RegSetValueExW(a0, a1, a2, a3, a4, a5);
269 // CFilterMapper2
272 IFilterMapper2* CFilterMapper2::m_pFilterMapper2 = NULL;
274 bool CFilterMapper2::fInitialized = false;
276 void CFilterMapper2::Init()
278 if(!fInitialized)
280 DetourFunctionWithTrampoline((PBYTE)Real_CoCreateInstance, (PBYTE)Mine_CoCreateInstance);
281 DetourFunctionWithTrampoline((PBYTE)Real_RegCloseKey, (PBYTE)Mine_RegCloseKey);
282 DetourFunctionWithTrampoline((PBYTE)Real_RegFlushKey, (PBYTE)Mine_RegFlushKey);
283 DetourFunctionWithTrampoline((PBYTE)Real_RegCreateKeyA, (PBYTE)Mine_RegCreateKeyA);
284 DetourFunctionWithTrampoline((PBYTE)Real_RegCreateKeyW, (PBYTE)Mine_RegCreateKeyW);
285 DetourFunctionWithTrampoline((PBYTE)Real_RegCreateKeyExA, (PBYTE)Mine_RegCreateKeyExA);
286 DetourFunctionWithTrampoline((PBYTE)Real_RegCreateKeyExW, (PBYTE)Mine_RegCreateKeyExW);
287 DetourFunctionWithTrampoline((PBYTE)Real_RegDeleteKeyA, (PBYTE)Mine_RegDeleteKeyA);
288 DetourFunctionWithTrampoline((PBYTE)Real_RegDeleteKeyW, (PBYTE)Mine_RegDeleteKeyW);
289 DetourFunctionWithTrampoline((PBYTE)Real_RegDeleteValueA, (PBYTE)Mine_RegDeleteValueA);
290 DetourFunctionWithTrampoline((PBYTE)Real_RegDeleteValueW, (PBYTE)Mine_RegDeleteValueW);
291 DetourFunctionWithTrampoline((PBYTE)Real_RegEnumKeyExA, (PBYTE)Mine_RegEnumKeyExA);
292 DetourFunctionWithTrampoline((PBYTE)Real_RegEnumKeyExW, (PBYTE)Mine_RegEnumKeyExW);
293 DetourFunctionWithTrampoline((PBYTE)Real_RegEnumValueA, (PBYTE)Mine_RegEnumValueA);
294 DetourFunctionWithTrampoline((PBYTE)Real_RegEnumValueW, (PBYTE)Mine_RegEnumValueW);
295 DetourFunctionWithTrampoline((PBYTE)Real_RegOpenKeyA, (PBYTE)Mine_RegOpenKeyA);
296 DetourFunctionWithTrampoline((PBYTE)Real_RegOpenKeyW, (PBYTE)Mine_RegOpenKeyW);
297 DetourFunctionWithTrampoline((PBYTE)Real_RegOpenKeyExA, (PBYTE)Mine_RegOpenKeyExA);
298 DetourFunctionWithTrampoline((PBYTE)Real_RegOpenKeyExW, (PBYTE)Mine_RegOpenKeyExW);
299 DetourFunctionWithTrampoline((PBYTE)Real_RegQueryInfoKeyA, (PBYTE)Mine_RegQueryInfoKeyA);
300 DetourFunctionWithTrampoline((PBYTE)Real_RegQueryInfoKeyW, (PBYTE)Mine_RegQueryInfoKeyW);
301 DetourFunctionWithTrampoline((PBYTE)Real_RegQueryValueA, (PBYTE)Mine_RegQueryValueA);
302 DetourFunctionWithTrampoline((PBYTE)Real_RegQueryValueW, (PBYTE)Mine_RegQueryValueW);
303 DetourFunctionWithTrampoline((PBYTE)Real_RegQueryValueExA, (PBYTE)Mine_RegQueryValueExA);
304 DetourFunctionWithTrampoline((PBYTE)Real_RegQueryValueExW, (PBYTE)Mine_RegQueryValueExW);
305 DetourFunctionWithTrampoline((PBYTE)Real_RegSetValueA, (PBYTE)Mine_RegSetValueA);
306 DetourFunctionWithTrampoline((PBYTE)Real_RegSetValueW, (PBYTE)Mine_RegSetValueW);
307 DetourFunctionWithTrampoline((PBYTE)Real_RegSetValueExA, (PBYTE)Mine_RegSetValueExA);
308 DetourFunctionWithTrampoline((PBYTE)Real_RegSetValueExW, (PBYTE)Mine_RegSetValueExW);
310 fInitialized = true;
314 CFilterMapper2::CFilterMapper2(bool fRefCounted, bool fAllowUnreg, LPUNKNOWN pUnkOuter)
315 : CUnknown(NAME("CFilterMapper2"), pUnkOuter)
316 , m_fRefCounted(fRefCounted), m_fAllowUnreg(fAllowUnreg)
318 m_cRef = fRefCounted ? 0 : 1;
320 Init();
322 HRESULT hr = Real_CoCreateInstance(
323 CLSID_FilterMapper2, (IUnknown*)(INonDelegatingUnknown*)this, CLSCTX_ALL,
324 __uuidof(IUnknown), (void**)&m_pFM2);
325 if(FAILED(hr) || !m_pFM2)
327 ASSERT(0);
328 return;
332 CFilterMapper2::~CFilterMapper2()
334 POSITION pos = m_filters.GetHeadPosition();
335 while(pos) delete m_filters.GetNext(pos);
338 STDMETHODIMP CFilterMapper2::NonDelegatingQueryInterface(REFIID riid, void** ppv)
340 if(riid == __uuidof(IFilterMapper2))
341 return GetInterface((IFilterMapper2*)this, ppv);
343 HRESULT hr = m_pFM2 ? m_pFM2->QueryInterface(riid, ppv) : E_NOINTERFACE;
345 return
346 SUCCEEDED(hr) ? hr :
347 __super::NonDelegatingQueryInterface(riid, ppv);
350 void CFilterMapper2::Register(CString path)
352 if(HMODULE h = LoadLibrary(path))
354 typedef HRESULT (__stdcall * PDllRegisterServer)();
355 if(PDllRegisterServer p = (PDllRegisterServer)GetProcAddress(h, "DllRegisterServer"))
357 ASSERT(CFilterMapper2::m_pFilterMapper2 == NULL);
359 CFilterMapper2::m_pFilterMapper2 = this;
360 m_path = path;
361 p();
362 m_path.Empty();
363 CFilterMapper2::m_pFilterMapper2 = NULL;
366 FreeLibrary(h);
370 // IFilterMapper2
372 STDMETHODIMP CFilterMapper2::CreateCategory(REFCLSID clsidCategory, DWORD dwCategoryMerit, LPCWSTR Description)
374 if(!m_path.IsEmpty())
376 return S_OK;
378 else if(CComQIPtr<IFilterMapper2> pFM2 = m_pFM2)
380 return pFM2->CreateCategory(clsidCategory, dwCategoryMerit, Description);
383 return E_NOTIMPL;
386 STDMETHODIMP CFilterMapper2::UnregisterFilter(const CLSID* pclsidCategory, const OLECHAR* szInstance, REFCLSID Filter)
388 if(!m_path.IsEmpty())
390 return S_OK;
392 else if(CComQIPtr<IFilterMapper2> pFM2 = m_pFM2)
394 return m_fAllowUnreg
395 ? pFM2->UnregisterFilter(pclsidCategory, szInstance, Filter)
396 : S_OK;
399 return E_NOTIMPL;
402 STDMETHODIMP CFilterMapper2::RegisterFilter(REFCLSID clsidFilter, LPCWSTR Name, IMoniker** ppMoniker, const CLSID* pclsidCategory, const OLECHAR* szInstance, const REGFILTER2* prf2)
404 if(!m_path.IsEmpty())
406 if(FilterOverride* f = new FilterOverride)
408 f->fDisabled = false;
409 f->type = FilterOverride::EXTERNAL;
410 f->path = m_path;
411 f->name = CStringW(Name);
412 f->clsid = clsidFilter;
413 f->iLoadType = FilterOverride::MERIT;
414 f->dwMerit = prf2->dwMerit;
416 if(prf2->dwVersion == 1)
418 for(ULONG i = 0; i < prf2->cPins; i++)
420 const REGFILTERPINS& rgPin = prf2->rgPins[i];
421 if(rgPin.bOutput) continue;
423 for(UINT i = 0; i < rgPin.nMediaTypes; i++)
425 if(!rgPin.lpMediaType[i].clsMajorType || !rgPin.lpMediaType[i].clsMinorType) break;
426 f->guids.AddTail(*rgPin.lpMediaType[i].clsMajorType);
427 f->guids.AddTail(*rgPin.lpMediaType[i].clsMinorType);
431 else if(prf2->dwVersion == 2)
433 for(ULONG i = 0; i < prf2->cPins2; i++)
435 const REGFILTERPINS2& rgPin = prf2->rgPins2[i];
436 if(rgPin.dwFlags&REG_PINFLAG_B_OUTPUT) continue;
438 for(UINT i = 0; i < rgPin.nMediaTypes; i++)
440 if(!rgPin.lpMediaType[i].clsMajorType || !rgPin.lpMediaType[i].clsMinorType) break;
441 f->guids.AddTail(*rgPin.lpMediaType[i].clsMajorType);
442 f->guids.AddTail(*rgPin.lpMediaType[i].clsMinorType);
447 f->backup.AddTailList(&f->guids);
449 m_filters.AddTail(f);
452 return S_OK;
454 else if(CComQIPtr<IFilterMapper2> pFM2 = m_pFM2)
456 return pFM2->RegisterFilter(clsidFilter, Name, ppMoniker, pclsidCategory, szInstance, prf2);
459 return E_NOTIMPL;
462 STDMETHODIMP CFilterMapper2::EnumMatchingFilters(IEnumMoniker** ppEnum, DWORD dwFlags, BOOL bExactMatch, DWORD dwMerit,
463 BOOL bInputNeeded, DWORD cInputTypes, const GUID* pInputTypes, const REGPINMEDIUM* pMedIn, const CLSID* pPinCategoryIn, BOOL bRender,
464 BOOL bOutputNeeded, DWORD cOutputTypes, const GUID* pOutputTypes, const REGPINMEDIUM* pMedOut, const CLSID* pPinCategoryOut)
466 if(CComQIPtr<IFilterMapper2> pFM2 = m_pFM2)
468 pFM2->EnumMatchingFilters(ppEnum, dwFlags, bExactMatch, dwMerit,
469 bInputNeeded, cInputTypes, pInputTypes, pMedIn, pPinCategoryIn, bRender,
470 bOutputNeeded, cOutputTypes, pOutputTypes, pMedOut, pPinCategoryOut);
473 return E_NOTIMPL;