ntdll: Make wine_build a hidden symbol.
[wine.git] / dlls / dmloader / dmloader_main.c
blob04e30fc791d103a212bf53eac59b60d49cf64278
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 LONG module_ref = 0;
41 typedef struct {
42 IClassFactory IClassFactory_iface;
43 HRESULT WINAPI (*fnCreateInstance)(REFIID riid, void **ppv);
44 } IClassFactoryImpl;
46 /******************************************************************
47 * IClassFactory implementation
49 static inline IClassFactoryImpl *impl_from_IClassFactory(IClassFactory *iface)
51 return CONTAINING_RECORD(iface, IClassFactoryImpl, IClassFactory_iface);
54 static HRESULT WINAPI ClassFactory_QueryInterface(IClassFactory *iface, REFIID riid, void **ppv)
56 if (ppv == NULL)
57 return E_POINTER;
59 if (IsEqualGUID(&IID_IUnknown, riid))
60 TRACE("(%p)->(IID_IUnknown %p)\n", iface, ppv);
61 else if (IsEqualGUID(&IID_IClassFactory, riid))
62 TRACE("(%p)->(IID_IClassFactory %p)\n", iface, ppv);
63 else {
64 FIXME("(%p)->(%s %p)\n", iface, debugstr_guid(riid), ppv);
65 *ppv = NULL;
66 return E_NOINTERFACE;
69 *ppv = iface;
70 IClassFactory_AddRef(iface);
71 return S_OK;
74 static ULONG WINAPI ClassFactory_AddRef(IClassFactory *iface)
76 lock_module();
78 return 2; /* non-heap based object */
81 static ULONG WINAPI ClassFactory_Release(IClassFactory *iface)
83 unlock_module();
85 return 1; /* non-heap based object */
88 static HRESULT WINAPI ClassFactory_CreateInstance(IClassFactory *iface, IUnknown *pUnkOuter,
89 REFIID riid, void **ret_iface)
91 IClassFactoryImpl *This = impl_from_IClassFactory(iface);
93 TRACE ("(%s, %p)\n", debugstr_dmguid(riid), ret_iface);
95 if (pUnkOuter) {
96 *ret_iface = NULL;
97 return CLASS_E_NOAGGREGATION;
100 return This->fnCreateInstance(riid, ret_iface);
103 static HRESULT WINAPI ClassFactory_LockServer(IClassFactory *iface, BOOL dolock)
105 TRACE("(%d)\n", dolock);
107 if (dolock)
108 lock_module();
109 else
110 unlock_module();
112 return S_OK;
115 static const IClassFactoryVtbl classfactory_vtbl = {
116 ClassFactory_QueryInterface,
117 ClassFactory_AddRef,
118 ClassFactory_Release,
119 ClassFactory_CreateInstance,
120 ClassFactory_LockServer
123 static IClassFactoryImpl dm_loader_CF = {{&classfactory_vtbl}, create_dmloader};
124 static IClassFactoryImpl dm_container_CF = {{&classfactory_vtbl}, create_dmcontainer};
126 /******************************************************************
127 * DllCanUnloadNow (DMLOADER.@)
129 HRESULT WINAPI DllCanUnloadNow (void)
131 TRACE("() ref=%d\n", module_ref);
133 return module_ref ? S_FALSE : S_OK;
136 /******************************************************************
137 * DllGetClassObject (DMLOADER.@)
139 HRESULT WINAPI DllGetClassObject (REFCLSID rclsid, REFIID riid, LPVOID *ppv)
141 TRACE("(%s, %s, %p)\n", debugstr_dmguid(rclsid), debugstr_dmguid(riid), ppv);
142 if (IsEqualCLSID (rclsid, &CLSID_DirectMusicLoader) && IsEqualIID (riid, &IID_IClassFactory)) {
143 IClassFactory_AddRef(&dm_loader_CF.IClassFactory_iface);
144 *ppv = &dm_loader_CF.IClassFactory_iface;
145 return S_OK;
146 } else if (IsEqualCLSID (rclsid, &CLSID_DirectMusicContainer) && IsEqualIID (riid, &IID_IClassFactory)) {
147 IClassFactory_AddRef(&dm_container_CF.IClassFactory_iface);
148 *ppv = &dm_container_CF.IClassFactory_iface;
149 return S_OK;
152 WARN(": no class found\n");
153 return CLASS_E_CLASSNOTAVAILABLE;