kernel32: Properly handle bare console on input.
[wine] / dlls / wbemprox / wbemlocator.c
1 /*
2  * Copyright 2009 Hans Leidekker for CodeWeavers
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 #define COBJMACROS
20
21 #include "config.h"
22 #include <stdarg.h>
23
24 #include "windef.h"
25 #include "winbase.h"
26 #include "initguid.h"
27 #include "objbase.h"
28 #include "wbemcli.h"
29
30 #include "wine/debug.h"
31 #include "wine/unicode.h"
32 #include "wbemprox_private.h"
33
34 WINE_DEFAULT_DEBUG_CHANNEL(wbemprox);
35
36 typedef struct
37 {
38     const IWbemLocatorVtbl *vtbl;
39     LONG refs;
40 } wbem_locator;
41
42 static inline wbem_locator *impl_from_IWbemLocator( IWbemLocator *iface )
43 {
44     return (wbem_locator *)((char *)iface - FIELD_OFFSET( wbem_locator, vtbl ));
45 }
46
47 static ULONG WINAPI wbem_locator_AddRef(
48     IWbemLocator *iface )
49 {
50     wbem_locator *wl = impl_from_IWbemLocator( iface );
51     return InterlockedIncrement( &wl->refs );
52 }
53
54 static ULONG WINAPI wbem_locator_Release(
55     IWbemLocator *iface )
56 {
57     wbem_locator *wl = impl_from_IWbemLocator( iface );
58     LONG refs = InterlockedDecrement( &wl->refs );
59     if (!refs)
60     {
61         TRACE("destroying %p\n", wl);
62         HeapFree( GetProcessHeap(), 0, wl );
63     }
64     return refs;
65 }
66
67 static HRESULT WINAPI wbem_locator_QueryInterface(
68     IWbemLocator *iface,
69     REFIID riid,
70     void **ppvObject )
71 {
72     wbem_locator *This = impl_from_IWbemLocator( iface );
73
74     TRACE("%p %s %p\n", This, debugstr_guid( riid ), ppvObject );
75
76     if ( IsEqualGUID( riid, &IID_IWbemLocator ) ||
77          IsEqualGUID( riid, &IID_IUnknown ) )
78     {
79         *ppvObject = iface;
80     }
81     else
82     {
83         FIXME("interface %s not implemented\n", debugstr_guid(riid));
84         return E_NOINTERFACE;
85     }
86     IWbemLocator_AddRef( iface );
87     return S_OK;
88 }
89
90 static HRESULT WINAPI wbem_locator_ConnectServer(
91     IWbemLocator *iface,
92     const BSTR NetworkResource,
93     const BSTR User,
94     const BSTR Password,
95     const BSTR Locale,
96     LONG SecurityFlags,
97     const BSTR Authority,
98     IWbemContext *pCtx,
99     IWbemServices **ppNamespace)
100 {
101     FIXME("%p, %s, %s, %s, %s, 0x%08x, %s, %p, %p)\n", iface, debugstr_w(NetworkResource), debugstr_w(User),
102           debugstr_w(Password), debugstr_w(Locale), SecurityFlags, debugstr_w(Authority), pCtx, ppNamespace);
103     return WBEM_E_FAILED;
104 }
105
106 static const IWbemLocatorVtbl wbem_locator_vtbl =
107 {
108     wbem_locator_QueryInterface,
109     wbem_locator_AddRef,
110     wbem_locator_Release,
111     wbem_locator_ConnectServer
112 };
113
114 HRESULT WbemLocator_create( IUnknown *pUnkOuter, LPVOID *ppObj )
115 {
116     wbem_locator *wl;
117
118     TRACE("(%p,%p)\n", pUnkOuter, ppObj);
119
120     wl = HeapAlloc( GetProcessHeap(), 0, sizeof(*wl) );
121     if (!wl) return E_OUTOFMEMORY;
122
123     wl->vtbl = &wbem_locator_vtbl;
124     wl->refs = 1;
125
126     *ppObj = &wl->vtbl;
127
128     TRACE("returning iface %p\n", *ppObj);
129     return S_OK;
130 }