widl: Always check the runtimeclass interfaces presence.
[wine/zf.git] / dlls / wmp / wmp_main.c
blob37ae9a1ac13a80fd7db7e9df6c81e550f0e1de85
1 /*
2 * Copyright 2014 Jacek Caban for CodeWeavers
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.
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.
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
19 #include "initguid.h"
20 #include "wmp_private.h"
21 #include "rpcproxy.h"
23 #include "wine/debug.h"
25 WINE_DEFAULT_DEBUG_CHANNEL(wmp);
27 HINSTANCE wmp_instance;
28 DEFINE_GUID(GUID_NULL,0,0,0,0,0,0,0,0,0,0,0);
30 static REFIID tid_ids[] = {
31 #define XIID(iface) &IID_ ## iface,
32 #define CTID(name) &CLSID_ ## name,
33 TID_LIST
34 #undef XIID
35 #undef CTID
38 static ITypeLib *typelib;
39 static ITypeInfo *typeinfos[LAST_tid];
41 static HRESULT load_typelib(void)
43 ITypeLib *tl;
44 HRESULT hr;
46 hr = LoadRegTypeLib(&LIBID_WMPLib, 1, 0, LOCALE_SYSTEM_DEFAULT, &tl);
47 if (FAILED(hr)) {
48 ERR("LoadRegTypeLib failed: %08x\n", hr);
49 return hr;
52 if (InterlockedCompareExchangePointer((void **)&typelib, tl, NULL))
53 ITypeLib_Release(tl);
54 return hr;
57 HRESULT get_typeinfo(typeinfo_id tid, ITypeInfo **typeinfo)
59 HRESULT hr;
61 if (!typelib)
62 hr = load_typelib();
63 if (!typelib)
64 return hr;
66 if (!typeinfos[tid]) {
67 ITypeInfo *ti;
69 hr = ITypeLib_GetTypeInfoOfGuid(typelib, tid_ids[tid], &ti);
70 if (FAILED(hr)) {
71 ERR("GetTypeInfoOfGuid (%s) failed: %08x\n", debugstr_guid(tid_ids[tid]), hr);
72 return hr;
75 if (InterlockedCompareExchangePointer((void **)(typeinfos + tid), ti, NULL))
76 ITypeInfo_Release(ti);
79 *typeinfo = typeinfos[tid];
80 ITypeInfo_AddRef(*typeinfo);
81 return S_OK;
84 static void release_typelib(void)
86 unsigned int i;
88 for (i = 0; i < ARRAY_SIZE(typeinfos); i++)
89 if (typeinfos[i])
90 ITypeInfo_Release(typeinfos[i]);
92 ITypeLib_Release(typelib);
95 static HRESULT WINAPI ClassFactory_QueryInterface(IClassFactory *iface, REFIID riid, void **ppv)
97 *ppv = NULL;
99 if(IsEqualGUID(&IID_IUnknown, riid)) {
100 TRACE("(%p)->(IID_IUnknown %p)\n", iface, ppv);
101 *ppv = iface;
102 }else if(IsEqualGUID(&IID_IClassFactory, riid)) {
103 TRACE("(%p)->(IID_IClassFactory %p)\n", iface, ppv);
104 *ppv = iface;
107 if(*ppv) {
108 IUnknown_AddRef((IUnknown*)*ppv);
109 return S_OK;
112 FIXME("(%p)->(%s %p)\n", iface, debugstr_guid(riid), ppv);
113 return E_NOINTERFACE;
116 static ULONG WINAPI ClassFactory_AddRef(IClassFactory *iface)
118 TRACE("(%p)\n", iface);
119 return 2;
122 static ULONG WINAPI ClassFactory_Release(IClassFactory *iface)
124 TRACE("(%p)\n", iface);
125 return 1;
128 static HRESULT WINAPI ClassFactory_LockServer(IClassFactory *iface, BOOL fLock)
130 TRACE("(%p)->(%x)\n", iface, fLock);
131 return S_OK;
134 static const IClassFactoryVtbl WMPFactoryVtbl = {
135 ClassFactory_QueryInterface,
136 ClassFactory_AddRef,
137 ClassFactory_Release,
138 WMPFactory_CreateInstance,
139 ClassFactory_LockServer
142 static IClassFactory WMPFactory = { &WMPFactoryVtbl };
144 /******************************************************************
145 * DllMain (wmp.@)
147 BOOL WINAPI DllMain(HINSTANCE hInstDLL, DWORD fdwReason, LPVOID lpv)
149 TRACE("(%p %d %p)\n", hInstDLL, fdwReason, lpv);
151 switch(fdwReason) {
152 case DLL_PROCESS_ATTACH:
153 DisableThreadLibraryCalls(hInstDLL);
154 wmp_instance = hInstDLL;
155 break;
156 case DLL_PROCESS_DETACH:
157 unregister_wmp_class();
158 unregister_player_msg_class();
159 release_typelib();
160 break;
163 return TRUE;
166 /***********************************************************************
167 * DllGetClassObject (wmp.@)
169 HRESULT WINAPI DllGetClassObject(REFCLSID rclsid, REFIID riid, LPVOID *ppv)
171 if(IsEqualGUID(&CLSID_WindowsMediaPlayer, rclsid)) {
172 TRACE("(CLSID_WindowsMediaPlayer %s %p)\n", debugstr_guid(riid), ppv);
173 return IClassFactory_QueryInterface(&WMPFactory, riid, ppv);
176 FIXME("Unknown object %s\n", debugstr_guid(rclsid));
177 return CLASS_E_CLASSNOTAVAILABLE;
180 /***********************************************************************
181 * DllCanUnloadNow (wmp.@)
183 HRESULT WINAPI DllCanUnloadNow(void)
185 TRACE("\n");
186 return S_FALSE;
189 /***********************************************************************
190 * DllRegisterServer (wmp.@)
192 HRESULT WINAPI DllRegisterServer(void)
194 TRACE("()\n");
195 return __wine_register_resources(wmp_instance);
198 /***********************************************************************
199 * DllUnregisterServer (wmp.@)
201 HRESULT WINAPI DllUnregisterServer(void)
203 TRACE("()\n");
204 return __wine_unregister_resources(wmp_instance);