Add a test for focus change on ShowWindow(child, SW_HIDE).
[wine] / dlls / dmloader / classfactory.c
1  /* IDirectMusicLoaderCF
2  *  IDirectMusicContainerCF
3  *
4  * Copyright (C) 2004 Rok Mandeljc
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU Library General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
19  */
20
21 #include "dmloader_private.h"
22
23 WINE_DEFAULT_DEBUG_CHANNEL(dmloader);
24
25 /*****************************************************************************
26  * IDirectMusicLoaderCF implementation
27  */
28 HRESULT WINAPI IDirectMusicLoaderCF_QueryInterface (LPCLASSFACTORY iface, REFIID riid, LPVOID *ppobj) {
29         ICOM_THIS(IDirectMusicLoaderCF, iface);
30         
31         TRACE("(%p, %s, %p)\n", This, debugstr_dmguid(riid), ppobj);
32         if (IsEqualIID (riid, &IID_IUnknown) || 
33             IsEqualIID (riid, &IID_IClassFactory)) {
34                 IDirectMusicLoaderCF_AddRef (iface);
35                 *ppobj = This;
36                 return S_OK;
37         }
38         
39         WARN(": not found\n");
40         return E_NOINTERFACE;
41 }
42
43 ULONG WINAPI IDirectMusicLoaderCF_AddRef (LPCLASSFACTORY iface) {
44         ICOM_THIS(IDirectMusicLoaderCF, iface);
45         TRACE("(%p): AddRef from %ld\n", This, This->dwRef);
46         return InterlockedIncrement (&This->dwRef);
47 }
48
49 ULONG WINAPI IDirectMusicLoaderCF_Release (LPCLASSFACTORY iface) {
50         ICOM_THIS(IDirectMusicLoaderCF, iface);
51         
52         DWORD dwRef = InterlockedDecrement (&This->dwRef);
53         TRACE("(%p): ReleaseRef to %ld\n", This, dwRef);
54         if (dwRef == 0) {
55                 HeapFree(GetProcessHeap (), 0, This);
56                 /* decrease number of instances */
57                 InterlockedDecrement(&dwDirectMusicLoader);
58         }
59         
60         return dwRef;   
61 }
62
63 HRESULT WINAPI IDirectMusicLoaderCF_CreateInstance (LPCLASSFACTORY iface, LPUNKNOWN pOuter, REFIID riid, LPVOID *ppobj) {
64         ICOM_THIS(IDirectMusicLoaderCF, iface);
65         
66         TRACE ("(%p, %p, %s, %p)\n", This, pOuter, debugstr_dmguid(riid), ppobj);
67         if (pOuter) {
68                 ERR(": pOuter should be NULL\n");
69                 return CLASS_E_NOAGGREGATION;
70         }
71         
72         return DMUSIC_CreateDirectMusicLoaderImpl (riid, ppobj, pOuter);
73 }
74
75 HRESULT WINAPI IDirectMusicLoaderCF_LockServer (LPCLASSFACTORY iface, BOOL dolock) {
76         ICOM_THIS(IDirectMusicLoaderCF, iface);
77         TRACE("(%p, %d)\n", This, dolock);
78         if (dolock == TRUE)
79                 InterlockedIncrement (&dwDirectMusicLoader);
80         else
81                 InterlockedDecrement (&dwDirectMusicLoader);
82         return S_OK;
83 }
84
85 ICOM_VTABLE(IClassFactory) DirectMusicLoaderCF_Vtbl = {
86         ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
87         IDirectMusicLoaderCF_QueryInterface,
88         IDirectMusicLoaderCF_AddRef,
89         IDirectMusicLoaderCF_Release,
90         IDirectMusicLoaderCF_CreateInstance,
91         IDirectMusicLoaderCF_LockServer
92 };
93
94 HRESULT WINAPI DMUSIC_CreateDirectMusicLoaderCF (LPCGUID lpcGUID, LPVOID *ppobj, LPUNKNOWN pUnkOuter) {
95         IDirectMusicLoaderCF *obj;
96
97         TRACE("(%s, %p, %p)\n", debugstr_dmguid(lpcGUID), ppobj, pUnkOuter);
98         obj = HeapAlloc (GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(IDirectMusicLoaderCF));
99         if (NULL == obj) {
100                 *ppobj = (LPCLASSFACTORY)NULL;
101                 return E_OUTOFMEMORY;
102         }
103         obj->lpVtbl = &DirectMusicLoaderCF_Vtbl;
104         obj->dwRef = 0; /* will be inited with QueryInterface */
105
106         /* increase number of instances */
107         InterlockedIncrement (&dwDirectMusicLoader);    
108         
109         return IDirectMusicLoaderCF_QueryInterface ((LPCLASSFACTORY)obj, lpcGUID, ppobj);
110 }
111
112
113 /*****************************************************************************
114  * IDirectMusicContainerCF implementation
115  */
116 HRESULT WINAPI IDirectMusicContainerCF_QueryInterface (LPCLASSFACTORY iface, REFIID riid, LPVOID *ppobj) {
117         ICOM_THIS(IDirectMusicContainerCF, iface);
118         
119         TRACE("(%p, %s, %p)\n", This, debugstr_dmguid(riid), ppobj);
120         if (IsEqualIID (riid, &IID_IUnknown) || 
121             IsEqualIID (riid, &IID_IClassFactory)) {
122                 IDirectMusicContainerCF_AddRef (iface);
123                 *ppobj = This;
124                 return S_OK;
125         }
126         
127         WARN(": not found\n");
128         return E_NOINTERFACE;
129 }
130
131 ULONG WINAPI IDirectMusicContainerCF_AddRef (LPCLASSFACTORY iface) {
132         ICOM_THIS(IDirectMusicContainerCF, iface);
133         TRACE("(%p): AddRef from %ld\n", This, This->dwRef);
134         return InterlockedIncrement (&This->dwRef);
135 }
136
137 ULONG WINAPI IDirectMusicContainerCF_Release (LPCLASSFACTORY iface) {
138         ICOM_THIS(IDirectMusicContainerCF, iface);
139         
140         DWORD dwRef = InterlockedDecrement (&This->dwRef);
141         TRACE("(%p): ReleaseRef to %ld\n", This, dwRef);
142         if (dwRef == 0) {
143                 HeapFree(GetProcessHeap (), 0, This);
144                 /* decrease number of instances */
145                 InterlockedDecrement(&dwDirectMusicContainer);
146         }
147         
148         return dwRef;
149 }
150
151 HRESULT WINAPI IDirectMusicContainerCF_CreateInstance (LPCLASSFACTORY iface, LPUNKNOWN pOuter, REFIID riid, LPVOID *ppobj) {
152         ICOM_THIS(IDirectMusicContainerCF, iface);
153
154         TRACE ("(%p, %p, %s, %p)\n", This, pOuter, debugstr_dmguid(riid), ppobj);
155         if (pOuter) {
156                 ERR(": pOuter should be NULL\n");
157                 return CLASS_E_NOAGGREGATION;
158         }
159
160         return DMUSIC_CreateDirectMusicContainerImpl (riid, ppobj, pOuter);
161 }
162
163 HRESULT WINAPI IDirectMusicContainerCF_LockServer (LPCLASSFACTORY iface, BOOL dolock) {
164         ICOM_THIS(IDirectMusicContainerCF, iface);
165         TRACE("(%p, %d)\n", This, dolock);
166         if (dolock == TRUE)
167                 InterlockedIncrement (&dwDirectMusicContainer);
168         else
169                 InterlockedDecrement (&dwDirectMusicContainer);
170         return S_OK;
171 }
172
173 ICOM_VTABLE(IClassFactory) DirectMusicContainerCF_Vtbl = {
174         ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
175         IDirectMusicContainerCF_QueryInterface,
176         IDirectMusicContainerCF_AddRef,
177         IDirectMusicContainerCF_Release,
178         IDirectMusicContainerCF_CreateInstance,
179         IDirectMusicContainerCF_LockServer
180 };
181
182 HRESULT WINAPI DMUSIC_CreateDirectMusicContainerCF (LPCGUID lpcGUID, LPVOID *ppobj, LPUNKNOWN pUnkOuter) {
183         IDirectMusicContainerCF *obj;
184
185         TRACE("(%s, %p, %p)\n", debugstr_dmguid(lpcGUID), ppobj, pUnkOuter);
186         obj = HeapAlloc (GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(IDirectMusicContainerCF));
187         if (NULL == obj) {
188                 *ppobj = (LPCLASSFACTORY)NULL;
189                 return E_OUTOFMEMORY;
190         }
191         obj->lpVtbl = &DirectMusicContainerCF_Vtbl;
192         obj->dwRef = 0; /* will be inited with QueryInterface */
193
194         /* increase number of instances */
195         InterlockedIncrement (&dwDirectMusicContainer);
196         
197         return IDirectMusicContainerCF_QueryInterface ((LPCLASSFACTORY)obj, lpcGUID, ppobj);
198 }