dwmapi: Clear DWM_TIMING_INFO structure before returning.
[wine.git] / dlls / combase / roapi.c
blob46adf0882477c728ef97a24be49d7249f2b7779a
1 /*
2 * Copyright 2014 Martin Storsjo
3 * Copyright 2016 Michael Müller
5 * This library 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 library 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 library; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
19 #define COBJMACROS
20 #include "objbase.h"
21 #include "initguid.h"
22 #include "roapi.h"
23 #include "roparameterizediid.h"
24 #include "roerrorapi.h"
25 #include "winstring.h"
27 #include "wine/debug.h"
29 WINE_DEFAULT_DEBUG_CHANNEL(combase);
31 static const char *debugstr_hstring(HSTRING hstr)
33 const WCHAR *str;
34 UINT32 len;
35 if (hstr && !((ULONG_PTR)hstr >> 16)) return "(invalid)";
36 str = WindowsGetStringRawBuffer(hstr, &len);
37 return wine_dbgstr_wn(str, len);
40 static HRESULT get_library_for_classid(const WCHAR *classid, WCHAR **out)
42 HKEY hkey_root, hkey_class;
43 DWORD type, size;
44 HRESULT hr;
45 WCHAR *buf = NULL;
47 *out = NULL;
49 /* load class registry key */
50 if (RegOpenKeyExW(HKEY_LOCAL_MACHINE, L"Software\\Microsoft\\WindowsRuntime\\ActivatableClassId",
51 0, KEY_READ, &hkey_root))
52 return REGDB_E_READREGDB;
53 if (RegOpenKeyExW(hkey_root, classid, 0, KEY_READ, &hkey_class))
55 WARN("Class %s not found in registry\n", debugstr_w(classid));
56 RegCloseKey(hkey_root);
57 return REGDB_E_CLASSNOTREG;
59 RegCloseKey(hkey_root);
61 /* load (and expand) DllPath registry value */
62 if (RegQueryValueExW(hkey_class, L"DllPath", NULL, &type, NULL, &size))
64 hr = REGDB_E_READREGDB;
65 goto done;
67 if (type != REG_SZ && type != REG_EXPAND_SZ)
69 hr = REGDB_E_READREGDB;
70 goto done;
72 if (!(buf = HeapAlloc(GetProcessHeap(), 0, size)))
74 hr = E_OUTOFMEMORY;
75 goto done;
77 if (RegQueryValueExW(hkey_class, L"DllPath", NULL, NULL, (BYTE *)buf, &size))
79 hr = REGDB_E_READREGDB;
80 goto done;
82 if (type == REG_EXPAND_SZ)
84 WCHAR *expanded;
85 DWORD len = ExpandEnvironmentStringsW(buf, NULL, 0);
86 if (!(expanded = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR))))
88 hr = E_OUTOFMEMORY;
89 goto done;
91 ExpandEnvironmentStringsW(buf, expanded, len);
92 HeapFree(GetProcessHeap(), 0, buf);
93 buf = expanded;
96 *out = buf;
97 return S_OK;
99 done:
100 HeapFree(GetProcessHeap(), 0, buf);
101 RegCloseKey(hkey_class);
102 return hr;
106 /***********************************************************************
107 * RoInitialize (combase.@)
109 HRESULT WINAPI RoInitialize(RO_INIT_TYPE type)
111 switch (type) {
112 case RO_INIT_SINGLETHREADED:
113 return CoInitializeEx(NULL, COINIT_APARTMENTTHREADED);
114 default:
115 FIXME("type %d\n", type);
116 case RO_INIT_MULTITHREADED:
117 return CoInitializeEx(NULL, COINIT_MULTITHREADED);
121 /***********************************************************************
122 * RoUninitialize (combase.@)
124 void WINAPI RoUninitialize(void)
126 CoUninitialize();
129 /***********************************************************************
130 * RoGetActivationFactory (combase.@)
132 HRESULT WINAPI RoGetActivationFactory(HSTRING classid, REFIID iid, void **class_factory)
134 PFNGETACTIVATIONFACTORY pDllGetActivationFactory;
135 IActivationFactory *factory;
136 WCHAR *library;
137 HMODULE module;
138 HRESULT hr;
140 FIXME("(%s, %s, %p): semi-stub\n", debugstr_hstring(classid), debugstr_guid(iid), class_factory);
142 if (!iid || !class_factory)
143 return E_INVALIDARG;
145 hr = get_library_for_classid(WindowsGetStringRawBuffer(classid, NULL), &library);
146 if (FAILED(hr))
148 ERR("Failed to find library for %s\n", debugstr_hstring(classid));
149 return hr;
152 if (!(module = LoadLibraryW(library)))
154 ERR("Failed to load module %s\n", debugstr_w(library));
155 hr = HRESULT_FROM_WIN32(GetLastError());
156 goto done;
159 if (!(pDllGetActivationFactory = (void *)GetProcAddress(module, "DllGetActivationFactory")))
161 ERR("Module %s does not implement DllGetActivationFactory\n", debugstr_w(library));
162 hr = E_FAIL;
163 goto done;
166 TRACE("Found library %s for class %s\n", debugstr_w(library), debugstr_hstring(classid));
168 hr = pDllGetActivationFactory(classid, &factory);
169 if (SUCCEEDED(hr))
171 hr = IActivationFactory_QueryInterface(factory, iid, class_factory);
172 if (SUCCEEDED(hr))
174 TRACE("Created interface %p\n", *class_factory);
175 module = NULL;
177 IActivationFactory_Release(factory);
180 done:
181 HeapFree(GetProcessHeap(), 0, library);
182 if (module) FreeLibrary(module);
183 return hr;
186 /***********************************************************************
187 * RoGetParameterizedTypeInstanceIID (combase.@)
189 HRESULT WINAPI RoGetParameterizedTypeInstanceIID(UINT32 name_element_count, const WCHAR **name_elements,
190 const IRoMetaDataLocator *meta_data_locator, GUID *iid,
191 ROPARAMIIDHANDLE *hiid)
193 FIXME("stub: %d %p %p %p %p\n", name_element_count, name_elements, meta_data_locator, iid, hiid);
194 if (iid) *iid = GUID_NULL;
195 if (hiid) *hiid = INVALID_HANDLE_VALUE;
196 return E_NOTIMPL;
199 /***********************************************************************
200 * RoActivateInstance (combase.@)
202 HRESULT WINAPI RoActivateInstance(HSTRING classid, IInspectable **instance)
204 IActivationFactory *factory;
205 HRESULT hr;
207 FIXME("(%p, %p): semi-stub\n", classid, instance);
209 hr = RoGetActivationFactory(classid, &IID_IActivationFactory, (void **)&factory);
210 if (SUCCEEDED(hr))
212 hr = IActivationFactory_ActivateInstance(factory, instance);
213 IActivationFactory_Release(factory);
216 return hr;
219 /***********************************************************************
220 * RoGetApartmentIdentifier (combase.@)
222 HRESULT WINAPI RoGetApartmentIdentifier(UINT64 *identifier)
224 FIXME("(%p): stub\n", identifier);
226 if (!identifier)
227 return E_INVALIDARG;
229 *identifier = 0xdeadbeef;
230 return S_OK;
233 /***********************************************************************
234 * RoRegisterForApartmentShutdown (combase.@)
236 HRESULT WINAPI RoRegisterForApartmentShutdown(IApartmentShutdown *callback,
237 UINT64 *identifier, APARTMENT_SHUTDOWN_REGISTRATION_COOKIE *cookie)
239 HRESULT hr;
241 FIXME("(%p, %p, %p): stub\n", callback, identifier, cookie);
243 hr = RoGetApartmentIdentifier(identifier);
244 if (FAILED(hr))
245 return hr;
247 if (cookie)
248 *cookie = (void *)0xcafecafe;
249 return S_OK;
252 /***********************************************************************
253 * RoGetServerActivatableClasses (combase.@)
255 HRESULT WINAPI RoGetServerActivatableClasses(HSTRING name, HSTRING **classes, DWORD *count)
257 FIXME("(%p, %p, %p): stub\n", name, classes, count);
259 if (count)
260 *count = 0;
261 return S_OK;
264 /***********************************************************************
265 * RoRegisterActivationFactories (combase.@)
267 HRESULT WINAPI RoRegisterActivationFactories(HSTRING *classes, PFNGETACTIVATIONFACTORY *callbacks,
268 UINT32 count, RO_REGISTRATION_COOKIE *cookie)
270 FIXME("(%p, %p, %d, %p): stub\n", classes, callbacks, count, cookie);
272 return S_OK;
275 /***********************************************************************
276 * GetRestrictedErrorInfo (combase.@)
278 HRESULT WINAPI GetRestrictedErrorInfo(IRestrictedErrorInfo **info)
280 FIXME( "(%p)\n", info );
281 return E_NOTIMPL;
284 /***********************************************************************
285 * RoOriginateLanguageException (combase.@)
287 BOOL WINAPI RoOriginateLanguageException(HRESULT error, HSTRING message, IUnknown *language_exception)
289 FIXME("%#lx, %s, %p: stub\n", error, debugstr_hstring(message), language_exception);
290 return FALSE;
293 /***********************************************************************
294 * RoOriginateError (combase.@)
296 BOOL WINAPI RoOriginateError(HRESULT error, HSTRING message)
298 FIXME("%#lx, %s: stub\n", error, debugstr_hstring(message));
299 return FALSE;
302 /***********************************************************************
303 * RoSetErrorReportingFlags (combase.@)
305 HRESULT WINAPI RoSetErrorReportingFlags(UINT32 flags)
307 FIXME("(%08x): stub\n", flags);
308 return S_OK;
311 /***********************************************************************
312 * CleanupTlsOleState (combase.@)
314 void WINAPI CleanupTlsOleState(void *unknown)
316 FIXME("(%p): stub\n", unknown);
319 /***********************************************************************
320 * DllGetActivationFactory (combase.@)
322 HRESULT WINAPI DllGetActivationFactory(HSTRING classid, IActivationFactory **factory)
324 FIXME("(%s, %p): stub\n", debugstr_hstring(classid), factory);
326 return REGDB_E_CLASSNOTREG;