netstat: Initial implementation.
[wine] / dlls / gameux / factory.c
1 /*
2  *    Gameux library IClassFactory implementation
3  *
4  * Copyright (C) 2010 Mariusz PluciƄski
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or (at your option) any later version.
10  *
11  * This library 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 GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this library; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
19  */
20
21 #define COBJMACROS
22
23 #include "config.h"
24
25 #include <stdarg.h>
26 #include "windef.h"
27 #include "winbase.h"
28 #include "ole2.h"
29
30 #include "gameux.h"
31 #include "gameux_private.h"
32
33 #include "wine/debug.h"
34
35 WINE_DEFAULT_DEBUG_CHANNEL(gameux);
36
37 typedef HRESULT (*fnCreateInstance)(IUnknown *pUnkOuter, IUnknown **ppObj);
38
39 /***************************************************************
40  * gameux ClassFactory
41  */
42 typedef struct _gameuxcf
43 {
44     IClassFactory IClassFactory_iface;
45     fnCreateInstance pfnCreateInstance;
46 } gameuxcf;
47
48 static inline gameuxcf *impl_from_IClassFactory(IClassFactory *iface)
49 {
50     return CONTAINING_RECORD(iface, gameuxcf, IClassFactory_iface);
51 }
52
53 static HRESULT WINAPI gameuxcf_QueryInterface(
54         IClassFactory *iface,
55         REFIID riid,
56         LPVOID *ppObj)
57 {
58     TRACE("(%p, %s, %p)\n", iface, debugstr_guid(riid), ppObj);
59
60     *ppObj = NULL;
61
62     if(IsEqualGUID(riid, &IID_IUnknown) ||
63        IsEqualGUID(riid, &IID_IClassFactory))
64     {
65         IClassFactory_AddRef(iface);
66         *ppObj = iface;
67         return S_OK;
68     }
69
70     FIXME("interface %s not implemented\n", debugstr_guid(riid));
71     return E_NOINTERFACE;
72 }
73
74 static ULONG WINAPI gameuxcf_AddRef(
75         IClassFactory *iface)
76 {
77     TRACE("(%p)\n", iface);
78     return 2;
79 }
80
81 static ULONG WINAPI gameuxcf_Release(
82         IClassFactory *iface)
83 {
84     TRACE("(%p)\n", iface);
85     return 1;
86 }
87
88 static HRESULT WINAPI gameuxcf_CreateInstance(
89         IClassFactory *iface,
90         LPUNKNOWN pUnkOuter,
91         REFIID riid,
92         LPVOID *ppObj)
93 {
94     gameuxcf *This = impl_from_IClassFactory(iface);
95     HRESULT hr;
96     IUnknown *pUnk;
97
98     TRACE("(%p, %p, %s, %p)\n", iface, pUnkOuter, debugstr_guid(riid), ppObj);
99
100     *ppObj = NULL;
101
102     if(pUnkOuter)
103         return CLASS_E_NOAGGREGATION;
104
105     hr = This->pfnCreateInstance(pUnkOuter, &pUnk);
106     if(FAILED(hr))
107         return hr;
108
109     hr = IUnknown_QueryInterface(pUnk, riid, ppObj);
110     IUnknown_Release(pUnk);
111     return hr;
112 }
113
114 static HRESULT WINAPI gameuxcf_LockServer(
115         IClassFactory *iface,
116         BOOL dolock)
117 {
118     gameuxcf *This = impl_from_IClassFactory(iface);
119     TRACE("(%p, %d)\n", This, dolock);
120     FIXME("stub\n");
121     return S_OK;
122 }
123
124 static const struct IClassFactoryVtbl gameuxcf_vtbl =
125 {
126     gameuxcf_QueryInterface,
127     gameuxcf_AddRef,
128     gameuxcf_Release,
129     gameuxcf_CreateInstance,
130     gameuxcf_LockServer
131 };
132
133 static gameuxcf gameexplorercf = { { &gameuxcf_vtbl }, GameExplorer_create };
134 static gameuxcf gamestatisticscf  = { { &gameuxcf_vtbl }, GameStatistics_create };
135
136 /***************************************************************
137  * gameux ClassFactory
138  */
139 HRESULT WINAPI DllGetClassObject(
140         REFCLSID rclsid,
141         REFIID riid,
142         LPVOID *ppv)
143 {
144     IClassFactory *cf = NULL;
145
146     TRACE("(%s, %s, %p)\n", debugstr_guid(rclsid), debugstr_guid(riid), ppv);
147
148     if(IsEqualCLSID(rclsid, &CLSID_GameExplorer))
149     {
150         cf = &gameexplorercf.IClassFactory_iface;
151     }
152     else if( IsEqualCLSID( rclsid, &CLSID_GameStatistics ))
153     {
154         cf = &gamestatisticscf.IClassFactory_iface;
155     }
156
157     if(!cf)
158         return CLASS_E_CLASSNOTAVAILABLE;
159
160     return IClassFactory_QueryInterface(cf, riid, ppv);
161 }