Sync with trunk (aka 'I want my virtualbox mouse integration too')
[reactos.git] / dll / win32 / hnetcfg / hnetcfg.c
1 /*
2 * Copyright (C) 2007 Jeff Latimer
3 *
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
8 *
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
13 *
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
17 */
18
19 #include <stdarg.h>
20
21 #define COBJMACROS
22
23 #include "windef.h"
24 #include "winbase.h"
25 #include "objbase.h"
26 #include "netfw.h"
27
28 #include "wine/debug.h"
29 #include "hnetcfg_private.h"
30
31 WINE_DEFAULT_DEBUG_CHANNEL(hnetcfg);
32
33 typedef HRESULT (*fnCreateInstance)( IUnknown *pUnkOuter, LPVOID *ppObj );
34
35 typedef struct
36 {
37 const struct IClassFactoryVtbl *vtbl;
38 fnCreateInstance pfnCreateInstance;
39 } hnetcfg_cf;
40
41 static inline hnetcfg_cf *impl_from_IClassFactory( IClassFactory *iface )
42 {
43 return (hnetcfg_cf *)((char *)iface - FIELD_OFFSET( hnetcfg_cf, vtbl ));
44 }
45
46 static HRESULT WINAPI hnetcfg_cf_QueryInterface( IClassFactory *iface, REFIID riid, LPVOID *ppobj )
47 {
48 if (IsEqualGUID(riid, &IID_IUnknown) ||
49 IsEqualGUID(riid, &IID_IClassFactory))
50 {
51 IClassFactory_AddRef( iface );
52 *ppobj = iface;
53 return S_OK;
54 }
55 FIXME("interface %s not implemented\n", debugstr_guid(riid));
56 return E_NOINTERFACE;
57 }
58
59 static ULONG WINAPI hnetcfg_cf_AddRef( IClassFactory *iface )
60 {
61 return 2;
62 }
63
64 static ULONG WINAPI hnetcfg_cf_Release( IClassFactory *iface )
65 {
66 return 1;
67 }
68
69 static HRESULT WINAPI hnetcfg_cf_CreateInstance( IClassFactory *iface, LPUNKNOWN pOuter,
70 REFIID riid, LPVOID *ppobj )
71 {
72 hnetcfg_cf *This = impl_from_IClassFactory( iface );
73 HRESULT r;
74 IUnknown *punk;
75
76 TRACE("%p %s %p\n", pOuter, debugstr_guid(riid), ppobj);
77
78 *ppobj = NULL;
79
80 if (pOuter)
81 return CLASS_E_NOAGGREGATION;
82
83 r = This->pfnCreateInstance( pOuter, (LPVOID *)&punk );
84 if (FAILED(r))
85 return r;
86
87 r = IUnknown_QueryInterface( punk, riid, ppobj );
88 if (FAILED(r))
89 return r;
90
91 IUnknown_Release( punk );
92 return r;
93 }
94
95 static HRESULT WINAPI hnetcfg_cf_LockServer( IClassFactory *iface, BOOL dolock )
96 {
97 FIXME("(%p)->(%d)\n", iface, dolock);
98 return S_OK;
99 }
100
101 static const struct IClassFactoryVtbl hnetcfg_cf_vtbl =
102 {
103 hnetcfg_cf_QueryInterface,
104 hnetcfg_cf_AddRef,
105 hnetcfg_cf_Release,
106 hnetcfg_cf_CreateInstance,
107 hnetcfg_cf_LockServer
108 };
109
110 static hnetcfg_cf fw_manager_cf = { &hnetcfg_cf_vtbl, NetFwMgr_create };
111 static hnetcfg_cf fw_app_cf = { &hnetcfg_cf_vtbl, NetFwAuthorizedApplication_create };
112
113 BOOL WINAPI DllMain(HINSTANCE hInstDLL, DWORD fdwReason, LPVOID lpvReserved)
114 {
115 TRACE("(0x%p, %d, %p)\n",hInstDLL,fdwReason,lpvReserved);
116
117 switch(fdwReason) {
118 case DLL_WINE_PREATTACH:
119 return FALSE;
120 case DLL_PROCESS_ATTACH:
121 DisableThreadLibraryCalls(hInstDLL);
122 break;
123 case DLL_PROCESS_DETACH:
124 break;
125 }
126 return TRUE;
127 }
128
129 HRESULT WINAPI DllGetClassObject( REFCLSID rclsid, REFIID iid, LPVOID *ppv )
130 {
131 IClassFactory *cf = NULL;
132
133 TRACE("%s %s %p\n", debugstr_guid(rclsid), debugstr_guid(iid), ppv);
134
135 if (IsEqualGUID( rclsid, &CLSID_NetFwMgr ))
136 {
137 cf = (IClassFactory *)&fw_manager_cf.vtbl;
138 }
139 else if (IsEqualGUID( rclsid, &CLSID_NetFwAuthorizedApplication ))
140 {
141 cf = (IClassFactory *)&fw_app_cf.vtbl;
142 }
143
144 if (!cf) return CLASS_E_CLASSNOTAVAILABLE;
145 return IClassFactory_QueryInterface( cf, iid, ppv );
146 }
147
148 HRESULT WINAPI DllCanUnloadNow( void )
149 {
150 return S_FALSE;
151 }