riched20: Implement GetForeColor().
[wine.git] / dlls / dmloader / dmloader_main.c
blobf02e523ab093f11f8dc789be891246ad549abccb
1 /* DirectMusicLoader Main
3 * Copyright (C) 2003-2004 Rok Mandeljc
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
20 #include <stdarg.h>
22 #define COBJMACROS
24 #include "windef.h"
25 #include "winbase.h"
26 #include "winnt.h"
27 #include "wingdi.h"
28 #include "winuser.h"
29 #include "winreg.h"
30 #include "objbase.h"
31 #include "rpcproxy.h"
32 #include "initguid.h"
33 #include "dmusici.h"
35 #include "dmloader_private.h"
37 WINE_DEFAULT_DEBUG_CHANNEL(dmloader);
39 static HINSTANCE instance;
40 LONG module_ref = 0;
42 typedef struct {
43 IClassFactory IClassFactory_iface;
44 HRESULT WINAPI (*fnCreateInstance)(REFIID riid, void **ppv);
45 } IClassFactoryImpl;
47 /******************************************************************
48 * IClassFactory implementation
50 static inline IClassFactoryImpl *impl_from_IClassFactory(IClassFactory *iface)
52 return CONTAINING_RECORD(iface, IClassFactoryImpl, IClassFactory_iface);
55 static HRESULT WINAPI ClassFactory_QueryInterface(IClassFactory *iface, REFIID riid, void **ppv)
57 if (ppv == NULL)
58 return E_POINTER;
60 if (IsEqualGUID(&IID_IUnknown, riid))
61 TRACE("(%p)->(IID_IUnknown %p)\n", iface, ppv);
62 else if (IsEqualGUID(&IID_IClassFactory, riid))
63 TRACE("(%p)->(IID_IClassFactory %p)\n", iface, ppv);
64 else {
65 FIXME("(%p)->(%s %p)\n", iface, debugstr_guid(riid), ppv);
66 *ppv = NULL;
67 return E_NOINTERFACE;
70 *ppv = iface;
71 IClassFactory_AddRef(iface);
72 return S_OK;
75 static ULONG WINAPI ClassFactory_AddRef(IClassFactory *iface)
77 lock_module();
79 return 2; /* non-heap based object */
82 static ULONG WINAPI ClassFactory_Release(IClassFactory *iface)
84 unlock_module();
86 return 1; /* non-heap based object */
89 static HRESULT WINAPI ClassFactory_CreateInstance(IClassFactory *iface, IUnknown *pUnkOuter,
90 REFIID riid, void **ret_iface)
92 IClassFactoryImpl *This = impl_from_IClassFactory(iface);
94 TRACE ("(%s, %p)\n", debugstr_dmguid(riid), ret_iface);
96 if (pUnkOuter) {
97 *ret_iface = NULL;
98 return CLASS_E_NOAGGREGATION;
101 return This->fnCreateInstance(riid, ret_iface);
104 static HRESULT WINAPI ClassFactory_LockServer(IClassFactory *iface, BOOL dolock)
106 TRACE("(%d)\n", dolock);
108 if (dolock)
109 lock_module();
110 else
111 unlock_module();
113 return S_OK;
116 static const IClassFactoryVtbl classfactory_vtbl = {
117 ClassFactory_QueryInterface,
118 ClassFactory_AddRef,
119 ClassFactory_Release,
120 ClassFactory_CreateInstance,
121 ClassFactory_LockServer
124 static IClassFactoryImpl dm_loader_CF = {{&classfactory_vtbl}, create_dmloader};
125 static IClassFactoryImpl dm_container_CF = {{&classfactory_vtbl}, create_dmcontainer};
127 /******************************************************************
128 * DllMain
130 BOOL WINAPI DllMain (HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved) {
131 if (fdwReason == DLL_PROCESS_ATTACH) {
132 instance = hinstDLL;
133 DisableThreadLibraryCalls(hinstDLL);
135 return TRUE;
139 /******************************************************************
140 * DllCanUnloadNow (DMLOADER.@)
142 HRESULT WINAPI DllCanUnloadNow (void)
144 TRACE("() ref=%d\n", module_ref);
146 return module_ref ? S_FALSE : S_OK;
149 /******************************************************************
150 * DllGetClassObject (DMLOADER.@)
152 HRESULT WINAPI DllGetClassObject (REFCLSID rclsid, REFIID riid, LPVOID *ppv)
154 TRACE("(%s, %s, %p)\n", debugstr_dmguid(rclsid), debugstr_dmguid(riid), ppv);
155 if (IsEqualCLSID (rclsid, &CLSID_DirectMusicLoader) && IsEqualIID (riid, &IID_IClassFactory)) {
156 IClassFactory_AddRef(&dm_loader_CF.IClassFactory_iface);
157 *ppv = &dm_loader_CF.IClassFactory_iface;
158 return S_OK;
159 } else if (IsEqualCLSID (rclsid, &CLSID_DirectMusicContainer) && IsEqualIID (riid, &IID_IClassFactory)) {
160 IClassFactory_AddRef(&dm_container_CF.IClassFactory_iface);
161 *ppv = &dm_container_CF.IClassFactory_iface;
162 return S_OK;
165 WARN(": no class found\n");
166 return CLASS_E_CLASSNOTAVAILABLE;
169 /***********************************************************************
170 * DllRegisterServer (DMLOADER.@)
172 HRESULT WINAPI DllRegisterServer(void)
174 return __wine_register_resources( instance );
177 /***********************************************************************
178 * DllUnregisterServer (DMLOADER.@)
180 HRESULT WINAPI DllUnregisterServer(void)
182 return __wine_unregister_resources( instance );