makefiles: Don't use standard libs for programs that specify -nodefaultlibs.
[wine/zf.git] / dlls / wmp / wmp_main.c
blob2541fc54ffbc8796f9af0d606fb7b650dd5a54c2
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_WINE_PREATTACH:
153 return FALSE; /* prefer native version */
154 case DLL_PROCESS_ATTACH:
155 DisableThreadLibraryCalls(hInstDLL);
156 wmp_instance = hInstDLL;
157 break;
158 case DLL_PROCESS_DETACH:
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;
182 /***********************************************************************
183 * DllCanUnloadNow (wmp.@)
185 HRESULT WINAPI DllCanUnloadNow(void)
187 TRACE("\n");
188 return S_FALSE;
191 /***********************************************************************
192 * DllRegisterServer (wmp.@)
194 HRESULT WINAPI DllRegisterServer(void)
196 TRACE("()\n");
197 return __wine_register_resources(wmp_instance);
200 /***********************************************************************
201 * DllUnregisterServer (wmp.@)
203 HRESULT WINAPI DllUnregisterServer(void)
205 TRACE("()\n");
206 return __wine_unregister_resources(wmp_instance);