Use Interlocked* functions in AddRef and Release.
[wine.git] / dlls / devenum / factory.c
blob8c5409b5ca5218af29f5f52a6816cafac0176ae5
1 /*
2 * ClassFactory implementation for DEVENUM.dll
4 * Copyright (C) 2002 John K. Hohm
5 * Copyright (C) 2002 Robert Shearman
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.
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.
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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 #include "devenum_private.h"
24 #include "wine/debug.h"
26 WINE_DEFAULT_DEBUG_CHANNEL(devenum);
28 /**********************************************************************
29 * DEVENUM_IClassFactory_QueryInterface (also IUnknown)
31 static HRESULT WINAPI DEVENUM_IClassFactory_QueryInterface(
32 LPCLASSFACTORY iface,
33 REFIID riid,
34 LPVOID *ppvObj)
36 ClassFactoryImpl *This = (ClassFactoryImpl *)iface;
37 TRACE("\n\tIID:\t%s\n",debugstr_guid(riid));
39 if (This == NULL || ppvObj == NULL) return E_POINTER;
41 if (IsEqualGUID(riid, &IID_IUnknown) ||
42 IsEqualGUID(riid, &IID_IClassFactory))
44 *ppvObj = (LPVOID)iface;
45 IClassFactory_AddRef(iface);
46 return S_OK;
48 else if (IsEqualGUID(riid, &IID_IParseDisplayName))
50 return IClassFactory_CreateInstance(iface, NULL, riid, ppvObj);
53 FIXME("- no interface\n\tIID:\t%s\n", debugstr_guid(riid));
54 return E_NOINTERFACE;
57 /**********************************************************************
58 * DEVENUM_IClassFactory_AddRef (also IUnknown)
60 static ULONG WINAPI DEVENUM_IClassFactory_AddRef(LPCLASSFACTORY iface)
62 ClassFactoryImpl *This = (ClassFactoryImpl *)iface;
63 TRACE("\n");
65 if (This == NULL) return E_POINTER;
67 This->ref++;
69 if (InterlockedIncrement(&This->ref) == 1) {
70 InterlockedIncrement(&dll_ref);
72 return This->ref;
75 /**********************************************************************
76 * DEVENUM_IClassFactory_Release (also IUnknown)
78 static ULONG WINAPI DEVENUM_IClassFactory_Release(LPCLASSFACTORY iface)
80 ClassFactoryImpl *This = (ClassFactoryImpl *)iface;
81 TRACE("\n");
83 if (This == NULL) return E_POINTER;
85 if (InterlockedDecrement(&This->ref) == 0) {
86 InterlockedDecrement(&dll_ref);
88 return This->ref;
91 /**********************************************************************
92 * DEVENUM_IClassFactory_CreateInstance
94 static HRESULT WINAPI DEVENUM_IClassFactory_CreateInstance(
95 LPCLASSFACTORY iface,
96 LPUNKNOWN pUnkOuter,
97 REFIID riid,
98 LPVOID *ppvObj)
100 ClassFactoryImpl *This = (ClassFactoryImpl *)iface;
101 TRACE("\n\tIID:\t%s\n",debugstr_guid(riid));
103 if (This == NULL || ppvObj == NULL) return E_POINTER;
105 /* Don't support aggregation (Windows doesn't) */
106 if (pUnkOuter != NULL) return CLASS_E_NOAGGREGATION;
108 if (IsEqualGUID(&IID_ICreateDevEnum, riid))
110 *ppvObj = &DEVENUM_CreateDevEnum;
111 return S_OK;
113 if (IsEqualGUID(&IID_IParseDisplayName, riid))
115 *ppvObj = &DEVENUM_ParseDisplayName;
116 return S_OK;
119 return CLASS_E_CLASSNOTAVAILABLE;
122 /**********************************************************************
123 * DEVENUM_IClassFactory_LockServer
125 static HRESULT WINAPI DEVENUM_IClassFactory_LockServer(
126 LPCLASSFACTORY iface,
127 BOOL fLock)
129 TRACE("\n");
131 if (fLock != FALSE) {
132 IClassFactory_AddRef(iface);
133 } else {
134 IClassFactory_Release(iface);
136 return S_OK;
139 /**********************************************************************
140 * IClassFactory_Vtbl
142 static IClassFactoryVtbl IClassFactory_Vtbl =
144 DEVENUM_IClassFactory_QueryInterface,
145 DEVENUM_IClassFactory_AddRef,
146 DEVENUM_IClassFactory_Release,
147 DEVENUM_IClassFactory_CreateInstance,
148 DEVENUM_IClassFactory_LockServer
151 /**********************************************************************
152 * static ClassFactory instance
154 ClassFactoryImpl DEVENUM_ClassFactory = { &IClassFactory_Vtbl, 0 };