rpcrt4: Add tests for a complex array of pointers.
[wine] / dlls / objsel / factory.c
1 /*
2  *      ClassFactory implementation for OBJSEL.dll
3  *
4  * Copyright (C) 2002 John K. Hohm
5  * Copyright (C) 2002 Robert Shearman
6  *
7  * This library is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU Lesser General Public
9  * License as published by the Free Software Foundation; either
10  * version 2.1 of the License, or (at your option) any later version.
11  *
12  * This library is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15  * Lesser General Public License for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public
18  * License along with this library; if not, write to the Free Software
19  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
20  */
21
22 #include "objsel_private.h"
23
24 #include "wine/debug.h"
25
26 WINE_DEFAULT_DEBUG_CHANNEL(objsel);
27
28
29 /**********************************************************************
30  * OBJSEL_IClassFactory_QueryInterface (also IUnknown)
31  */
32 static HRESULT WINAPI OBJSEL_IClassFactory_QueryInterface(
33     LPCLASSFACTORY iface,
34     REFIID riid,
35     LPVOID *ppvObj)
36 {
37     TRACE("\n\tIID:\t%s\n",debugstr_guid(riid));
38
39     if (ppvObj == NULL) return E_POINTER;
40
41     if (IsEqualGUID(riid, &IID_IUnknown) ||
42         IsEqualGUID(riid, &IID_IClassFactory))
43     {
44         *ppvObj = iface;
45         IClassFactory_AddRef(iface);
46         return S_OK;
47     }
48     else if (IsEqualGUID(riid, &IID_IDsObjectPicker))
49     {
50         return IClassFactory_CreateInstance(iface, NULL, riid, ppvObj);
51     }
52
53     FIXME("- no interface IID: %s\n", debugstr_guid(riid));
54     return E_NOINTERFACE;
55 }
56
57
58 /**********************************************************************
59  * OBJSEL_IClassFactory_AddRef (also IUnknown)
60  */
61 static ULONG WINAPI OBJSEL_IClassFactory_AddRef(LPCLASSFACTORY iface)
62 {
63     ClassFactoryImpl *This = (ClassFactoryImpl *)iface;
64     ULONG ref;
65     
66     TRACE("\n");
67
68     if (This == NULL) return E_POINTER;
69     
70     ref = InterlockedIncrement(&This->ref);
71     
72     if (ref == 1)
73     {
74         InterlockedIncrement(&dll_refs);
75     }
76
77     return ref;
78 }
79
80
81 /**********************************************************************
82  * OBJSEL_IClassFactory_Release (also IUnknown)
83  */
84 static ULONG WINAPI OBJSEL_IClassFactory_Release(LPCLASSFACTORY iface)
85 {
86     ClassFactoryImpl *This = (ClassFactoryImpl *)iface;
87     ULONG ref;
88     
89     TRACE("\n");
90
91     if (This == NULL) return E_POINTER;
92     
93     ref = InterlockedDecrement(&This->ref);
94     
95     if (ref == 0)
96     {
97         InterlockedDecrement(&dll_refs);
98     }
99
100     return ref;
101 }
102
103
104 /**********************************************************************
105  * OBJSEL_IClassFactory_CreateInstance
106  */
107 static HRESULT WINAPI OBJSEL_IClassFactory_CreateInstance(
108     LPCLASSFACTORY iface,
109     LPUNKNOWN pUnkOuter,
110     REFIID riid,
111     LPVOID *ppvObj)
112 {
113     TRACE("\n\tIID:\t%s\n",debugstr_guid(riid));
114
115     if (ppvObj == NULL) return E_POINTER;
116
117     /* Don't support aggregation (Windows doesn't) */
118     if (pUnkOuter != NULL) return CLASS_E_NOAGGREGATION;
119
120     if (IsEqualGUID(&IID_IDsObjectPicker, riid))
121     {
122         return OBJSEL_IDsObjectPicker_Create(ppvObj);
123     }
124
125     return CLASS_E_CLASSNOTAVAILABLE;
126 }
127
128
129 /**********************************************************************
130  * OBJSEL_IClassFactory_LockServer
131  */
132 static HRESULT WINAPI OBJSEL_IClassFactory_LockServer(
133     LPCLASSFACTORY iface,
134     BOOL fLock)
135 {
136     TRACE("\n");
137
138     if (fLock)
139         IClassFactory_AddRef(iface);
140     else
141         IClassFactory_Release(iface);
142     return S_OK;
143 }
144
145
146 /**********************************************************************
147  * IClassFactory_Vtbl
148  */
149 static IClassFactoryVtbl IClassFactory_Vtbl =
150 {
151     OBJSEL_IClassFactory_QueryInterface,
152     OBJSEL_IClassFactory_AddRef,
153     OBJSEL_IClassFactory_Release,
154     OBJSEL_IClassFactory_CreateInstance,
155     OBJSEL_IClassFactory_LockServer
156 };
157
158
159 /**********************************************************************
160  * static ClassFactory instance
161  */
162
163 ClassFactoryImpl OBJSEL_ClassFactory = { &IClassFactory_Vtbl, 0 };