secur32: Eliminate broken clean-up "cheat".
[wine] / dlls / objsel / objsel.c
1 /*
2  * Object Picker Dialog
3  *
4  * Copyright 2005 Thomas Weidenmueller <w3seek@reactos.com>
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 #include "objsel_private.h"
22 #include "rpcproxy.h"
23
24 #include "wine/debug.h"
25
26 WINE_DEFAULT_DEBUG_CHANNEL(objsel);
27
28 LONG dll_refs = 0;
29 static HINSTANCE hInstance;
30
31 /***********************************************************************
32  *              DllEntryPoint
33  */
34 BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID fImpLoad)
35 {
36     switch(fdwReason)
37     {
38         case DLL_PROCESS_ATTACH:
39             hInstance = hinstDLL;
40             DisableThreadLibraryCalls(hInstance);
41             break;
42     }
43     return TRUE;
44 }
45
46
47 /***********************************************************************
48  *              DllGetClassObject (OBJSEL.@)
49  */
50 HRESULT WINAPI DllGetClassObject(REFCLSID rclsid, REFIID iid, LPVOID *ppv)
51 {
52     TRACE("(%s, %s, %p)\n", debugstr_guid(rclsid), debugstr_guid(iid), ppv);
53
54     *ppv = NULL;
55
56     if (IsEqualGUID(rclsid, &CLSID_DsObjectPicker))
57         return IClassFactory_QueryInterface(&OBJSEL_ClassFactory.IClassFactory_iface, iid, ppv);
58
59     FIXME("CLSID: %s, IID: %s\n", debugstr_guid(rclsid), debugstr_guid(iid));
60     return CLASS_E_CLASSNOTAVAILABLE;
61 }
62
63
64 /***********************************************************************
65  *              DllCanUnloadNow (OBJSEL.@)
66  */
67 HRESULT WINAPI DllCanUnloadNow(void)
68 {
69     return dll_refs != 0 ? S_FALSE : S_OK;
70 }
71
72
73 /***********************************************************************
74  *              DllRegisterServer (OBJSEL.@)
75  */
76 HRESULT WINAPI DllRegisterServer(void)
77 {
78     return __wine_register_resources( hInstance );
79 }
80
81
82 /***********************************************************************
83  *              DllUnregisterServer (OBJSEL.@)
84  */
85 HRESULT WINAPI DllUnregisterServer(void)
86 {
87     return __wine_unregister_resources( hInstance );
88 }
89
90
91 /**********************************************************************
92  * OBJSEL_IDsObjectPicker_Destroy (also IUnknown)
93  */
94 static VOID OBJSEL_IDsObjectPicker_Destroy(IDsObjectPickerImpl *This)
95 {
96     HeapFree(GetProcessHeap(),
97              0,
98              This);
99 }
100
101
102 static inline IDsObjectPickerImpl *impl_from_IDsObjectPicker(IDsObjectPicker *iface)
103 {
104     return CONTAINING_RECORD(iface, IDsObjectPickerImpl, IDsObjectPicker_iface);
105 }
106
107 /**********************************************************************
108  * OBJSEL_IDsObjectPicker_AddRef (also IUnknown)
109  */
110 static ULONG WINAPI OBJSEL_IDsObjectPicker_AddRef(IDsObjectPicker * iface)
111 {
112     IDsObjectPickerImpl *This = impl_from_IDsObjectPicker(iface);
113     ULONG ref;
114
115     TRACE("\n");
116
117     if (This == NULL) return E_POINTER;
118
119     ref = InterlockedIncrement(&This->ref);
120
121     if (ref == 1)
122     {
123         InterlockedIncrement(&dll_refs);
124     }
125
126     return ref;
127 }
128
129
130 /**********************************************************************
131  * OBJSEL_IDsObjectPicker_Release (also IUnknown)
132  */
133 static ULONG WINAPI OBJSEL_IDsObjectPicker_Release(IDsObjectPicker * iface)
134 {
135     IDsObjectPickerImpl *This = impl_from_IDsObjectPicker(iface);
136     ULONG ref;
137
138     TRACE("\n");
139
140     if (This == NULL) return E_POINTER;
141
142     ref = InterlockedDecrement(&This->ref);
143
144     if (ref == 0)
145     {
146         InterlockedDecrement(&dll_refs);
147         OBJSEL_IDsObjectPicker_Destroy(This);
148     }
149
150     return ref;
151 }
152
153
154 /**********************************************************************
155  * OBJSEL_IDsObjectPicker_QueryInterface (also IUnknown)
156  */
157 static HRESULT WINAPI OBJSEL_IDsObjectPicker_QueryInterface(
158     IDsObjectPicker * iface,
159     REFIID riid,
160     LPVOID *ppvObj)
161 {
162     TRACE("\n\tIID:\t%s\n",debugstr_guid(riid));
163
164     if (ppvObj == NULL) return E_POINTER;
165
166     if (IsEqualGUID(riid, &IID_IUnknown) ||
167         IsEqualGUID(riid, &IID_IDsObjectPicker))
168     {
169         *ppvObj = iface;
170         OBJSEL_IDsObjectPicker_AddRef(iface);
171         return S_OK;
172     }
173
174     FIXME("- no interface IID: %s\n", debugstr_guid(riid));
175     return E_NOINTERFACE;
176 }
177
178
179 /**********************************************************************
180  * OBJSEL_IDsObjectPicker_Initialize
181  */
182 static HRESULT WINAPI OBJSEL_IDsObjectPicker_Initialize(
183     IDsObjectPicker * iface,
184     PDSOP_INIT_INFO pInitInfo)
185 {
186     FIXME("stub!\n");
187     return S_OK;
188 }
189
190
191 /**********************************************************************
192  * OBJSEL_IDsObjectPicker_InvokeDialog
193  */
194 static HRESULT WINAPI OBJSEL_IDsObjectPicker_InvokeDialog(
195     IDsObjectPicker * iface,
196     HWND hwndParent,
197     IDataObject** ppdoSelections)
198 {
199     FIXME("stub!\n");
200     return S_FALSE;
201 }
202
203
204 /**********************************************************************
205  * IDsObjectPicker_Vtbl
206  */
207 static IDsObjectPickerVtbl IDsObjectPicker_Vtbl =
208 {
209     OBJSEL_IDsObjectPicker_QueryInterface,
210     OBJSEL_IDsObjectPicker_AddRef,
211     OBJSEL_IDsObjectPicker_Release,
212     OBJSEL_IDsObjectPicker_Initialize,
213     OBJSEL_IDsObjectPicker_InvokeDialog
214 };
215
216
217 /**********************************************************************
218  * OBJSEL_IDsObjectPicker_Create
219  */
220 HRESULT WINAPI OBJSEL_IDsObjectPicker_Create(LPVOID *ppvObj)
221 {
222     IDsObjectPickerImpl *Instance = HeapAlloc(GetProcessHeap(),
223                                               HEAP_ZERO_MEMORY,
224                                               sizeof(IDsObjectPickerImpl));
225     if (Instance != NULL)
226     {
227         Instance->IDsObjectPicker_iface.lpVtbl = &IDsObjectPicker_Vtbl;
228         OBJSEL_IDsObjectPicker_AddRef(&Instance->IDsObjectPicker_iface);
229
230         *ppvObj = Instance;
231         return S_OK;
232     }
233     else
234         return E_OUTOFMEMORY;
235 }