ntdll: Add ACTCTX field limit checks to RtlCreateActivationContext().
[wine.git] / dlls / wmp / wmp_main.c
blob2edaaf46df2d3bb194bea1cca66423d4973c5d97
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: %08lx\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: %08lx\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 if (typelib)
93 ITypeLib_Release(typelib);
96 static HRESULT WINAPI ClassFactory_QueryInterface(IClassFactory *iface, REFIID riid, void **ppv)
98 *ppv = NULL;
100 if(IsEqualGUID(&IID_IUnknown, riid)) {
101 TRACE("(%p)->(IID_IUnknown %p)\n", iface, ppv);
102 *ppv = iface;
103 }else if(IsEqualGUID(&IID_IClassFactory, riid)) {
104 TRACE("(%p)->(IID_IClassFactory %p)\n", iface, ppv);
105 *ppv = iface;
108 if(*ppv) {
109 IUnknown_AddRef((IUnknown*)*ppv);
110 return S_OK;
113 FIXME("(%p)->(%s %p)\n", iface, debugstr_guid(riid), ppv);
114 return E_NOINTERFACE;
117 static ULONG WINAPI ClassFactory_AddRef(IClassFactory *iface)
119 TRACE("(%p)\n", iface);
120 return 2;
123 static ULONG WINAPI ClassFactory_Release(IClassFactory *iface)
125 TRACE("(%p)\n", iface);
126 return 1;
129 static HRESULT WINAPI ClassFactory_LockServer(IClassFactory *iface, BOOL fLock)
131 TRACE("(%p)->(%x)\n", iface, fLock);
132 return S_OK;
135 static const IClassFactoryVtbl WMPFactoryVtbl = {
136 ClassFactory_QueryInterface,
137 ClassFactory_AddRef,
138 ClassFactory_Release,
139 WMPFactory_CreateInstance,
140 ClassFactory_LockServer
143 static IClassFactory WMPFactory = { &WMPFactoryVtbl };
145 /******************************************************************
146 * DllMain (wmp.@)
148 BOOL WINAPI DllMain(HINSTANCE hInstDLL, DWORD fdwReason, LPVOID lpv)
150 TRACE("(%p %ld %p)\n", hInstDLL, fdwReason, lpv);
152 switch(fdwReason) {
153 case DLL_PROCESS_ATTACH:
154 DisableThreadLibraryCalls(hInstDLL);
155 wmp_instance = hInstDLL;
156 break;
157 case DLL_PROCESS_DETACH:
158 if (lpv) break;
159 unregister_wmp_class();
160 unregister_player_msg_class();
161 release_typelib();
162 break;
165 return TRUE;
168 /***********************************************************************
169 * DllGetClassObject (wmp.@)
171 HRESULT WINAPI DllGetClassObject(REFCLSID rclsid, REFIID riid, LPVOID *ppv)
173 if(IsEqualGUID(&CLSID_WindowsMediaPlayer, rclsid)) {
174 TRACE("(CLSID_WindowsMediaPlayer %s %p)\n", debugstr_guid(riid), ppv);
175 return IClassFactory_QueryInterface(&WMPFactory, riid, ppv);
178 FIXME("Unknown object %s\n", debugstr_guid(rclsid));
179 return CLASS_E_CLASSNOTAVAILABLE;