include: Add STORAGE_HOTPLUG_INFO structure.
[wine.git] / dlls / combase / roapi.c
blob02d9e0b536e68f41d5bb21f197d22f57a8711787
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 "combase_private.h"
29 #include "wine/debug.h"
31 WINE_DEFAULT_DEBUG_CHANNEL(combase);
33 struct activatable_class_data
35 ULONG size;
36 DWORD unk;
37 DWORD module_len;
38 DWORD module_offset;
39 DWORD threading_model;
42 static HRESULT get_library_for_classid(const WCHAR *classid, WCHAR **out)
44 ACTCTX_SECTION_KEYED_DATA data;
45 HKEY hkey_root, hkey_class;
46 DWORD type, size;
47 HRESULT hr;
48 WCHAR *buf = NULL;
50 *out = NULL;
52 /* search activation context first */
53 data.cbSize = sizeof(data);
54 if (FindActCtxSectionStringW(FIND_ACTCTX_SECTION_KEY_RETURN_HACTCTX, NULL,
55 ACTIVATION_CONTEXT_SECTION_WINRT_ACTIVATABLE_CLASSES, classid, &data))
57 struct activatable_class_data *activatable_class = (struct activatable_class_data *)data.lpData;
58 void *ptr = (BYTE *)data.lpSectionBase + activatable_class->module_offset;
59 *out = wcsdup(ptr);
60 return S_OK;
63 /* load class registry key */
64 if (RegOpenKeyExW(HKEY_LOCAL_MACHINE, L"Software\\Microsoft\\WindowsRuntime\\ActivatableClassId",
65 0, KEY_READ, &hkey_root))
66 return REGDB_E_READREGDB;
67 if (RegOpenKeyExW(hkey_root, classid, 0, KEY_READ, &hkey_class))
69 WARN("Class %s not found in registry\n", debugstr_w(classid));
70 RegCloseKey(hkey_root);
71 return REGDB_E_CLASSNOTREG;
73 RegCloseKey(hkey_root);
75 /* load (and expand) DllPath registry value */
76 if (RegQueryValueExW(hkey_class, L"DllPath", NULL, &type, NULL, &size))
78 hr = REGDB_E_READREGDB;
79 goto done;
81 if (type != REG_SZ && type != REG_EXPAND_SZ)
83 hr = REGDB_E_READREGDB;
84 goto done;
86 if (!(buf = malloc(size)))
88 hr = E_OUTOFMEMORY;
89 goto done;
91 if (RegQueryValueExW(hkey_class, L"DllPath", NULL, NULL, (BYTE *)buf, &size))
93 hr = REGDB_E_READREGDB;
94 goto done;
96 if (type == REG_EXPAND_SZ)
98 WCHAR *expanded;
99 DWORD len = ExpandEnvironmentStringsW(buf, NULL, 0);
100 if (!(expanded = malloc(len * sizeof(WCHAR))))
102 hr = E_OUTOFMEMORY;
103 goto done;
105 ExpandEnvironmentStringsW(buf, expanded, len);
106 free(buf);
107 buf = expanded;
110 *out = buf;
111 return S_OK;
113 done:
114 free(buf);
115 RegCloseKey(hkey_class);
116 return hr;
120 /***********************************************************************
121 * RoInitialize (combase.@)
123 HRESULT WINAPI RoInitialize(RO_INIT_TYPE type)
125 switch (type) {
126 case RO_INIT_SINGLETHREADED:
127 return CoInitializeEx(NULL, COINIT_APARTMENTTHREADED);
128 default:
129 FIXME("type %d\n", type);
130 case RO_INIT_MULTITHREADED:
131 return CoInitializeEx(NULL, COINIT_MULTITHREADED);
135 /***********************************************************************
136 * RoUninitialize (combase.@)
138 void WINAPI RoUninitialize(void)
140 CoUninitialize();
143 /***********************************************************************
144 * RoGetActivationFactory (combase.@)
146 HRESULT WINAPI DECLSPEC_HOTPATCH RoGetActivationFactory(HSTRING classid, REFIID iid, void **class_factory)
148 PFNGETACTIVATIONFACTORY pDllGetActivationFactory;
149 IActivationFactory *factory;
150 WCHAR *library;
151 HMODULE module;
152 HRESULT hr;
154 FIXME("(%s, %s, %p): semi-stub\n", debugstr_hstring(classid), debugstr_guid(iid), class_factory);
156 if (!iid || !class_factory)
157 return E_INVALIDARG;
159 if (FAILED(hr = ensure_mta()))
160 return hr;
162 hr = get_library_for_classid(WindowsGetStringRawBuffer(classid, NULL), &library);
163 if (FAILED(hr))
165 ERR("Failed to find library for %s\n", debugstr_hstring(classid));
166 return hr;
169 if (!(module = LoadLibraryW(library)))
171 ERR("Failed to load module %s\n", debugstr_w(library));
172 hr = HRESULT_FROM_WIN32(GetLastError());
173 goto done;
176 if (!(pDllGetActivationFactory = (void *)GetProcAddress(module, "DllGetActivationFactory")))
178 ERR("Module %s does not implement DllGetActivationFactory\n", debugstr_w(library));
179 hr = E_FAIL;
180 goto done;
183 TRACE("Found library %s for class %s\n", debugstr_w(library), debugstr_hstring(classid));
185 hr = pDllGetActivationFactory(classid, &factory);
186 if (SUCCEEDED(hr))
188 hr = IActivationFactory_QueryInterface(factory, iid, class_factory);
189 if (SUCCEEDED(hr))
191 TRACE("Created interface %p\n", *class_factory);
192 module = NULL;
194 IActivationFactory_Release(factory);
197 done:
198 free(library);
199 if (module) FreeLibrary(module);
200 return hr;
203 /***********************************************************************
204 * RoGetParameterizedTypeInstanceIID (combase.@)
206 HRESULT WINAPI RoGetParameterizedTypeInstanceIID(UINT32 name_element_count, const WCHAR **name_elements,
207 const IRoMetaDataLocator *meta_data_locator, GUID *iid,
208 ROPARAMIIDHANDLE *hiid)
210 FIXME("stub: %d %p %p %p %p\n", name_element_count, name_elements, meta_data_locator, iid, hiid);
211 if (iid) *iid = GUID_NULL;
212 if (hiid) *hiid = INVALID_HANDLE_VALUE;
213 return E_NOTIMPL;
216 /***********************************************************************
217 * RoActivateInstance (combase.@)
219 HRESULT WINAPI RoActivateInstance(HSTRING classid, IInspectable **instance)
221 IActivationFactory *factory;
222 HRESULT hr;
224 FIXME("(%p, %p): semi-stub\n", classid, instance);
226 hr = RoGetActivationFactory(classid, &IID_IActivationFactory, (void **)&factory);
227 if (SUCCEEDED(hr))
229 hr = IActivationFactory_ActivateInstance(factory, instance);
230 IActivationFactory_Release(factory);
233 return hr;
236 /***********************************************************************
237 * RoGetApartmentIdentifier (combase.@)
239 HRESULT WINAPI RoGetApartmentIdentifier(UINT64 *identifier)
241 FIXME("(%p): stub\n", identifier);
243 if (!identifier)
244 return E_INVALIDARG;
246 *identifier = 0xdeadbeef;
247 return S_OK;
250 /***********************************************************************
251 * RoRegisterForApartmentShutdown (combase.@)
253 HRESULT WINAPI RoRegisterForApartmentShutdown(IApartmentShutdown *callback,
254 UINT64 *identifier, APARTMENT_SHUTDOWN_REGISTRATION_COOKIE *cookie)
256 HRESULT hr;
258 FIXME("(%p, %p, %p): stub\n", callback, identifier, cookie);
260 hr = RoGetApartmentIdentifier(identifier);
261 if (FAILED(hr))
262 return hr;
264 if (cookie)
265 *cookie = (void *)0xcafecafe;
266 return S_OK;
269 /***********************************************************************
270 * RoGetServerActivatableClasses (combase.@)
272 HRESULT WINAPI RoGetServerActivatableClasses(HSTRING name, HSTRING **classes, DWORD *count)
274 FIXME("(%p, %p, %p): stub\n", name, classes, count);
276 if (count)
277 *count = 0;
278 return S_OK;
281 /***********************************************************************
282 * RoRegisterActivationFactories (combase.@)
284 HRESULT WINAPI RoRegisterActivationFactories(HSTRING *classes, PFNGETACTIVATIONFACTORY *callbacks,
285 UINT32 count, RO_REGISTRATION_COOKIE *cookie)
287 FIXME("(%p, %p, %d, %p): stub\n", classes, callbacks, count, cookie);
289 return S_OK;
292 /***********************************************************************
293 * GetRestrictedErrorInfo (combase.@)
295 HRESULT WINAPI GetRestrictedErrorInfo(IRestrictedErrorInfo **info)
297 FIXME( "(%p)\n", info );
298 return E_NOTIMPL;
301 /***********************************************************************
302 * RoOriginateLanguageException (combase.@)
304 BOOL WINAPI RoOriginateLanguageException(HRESULT error, HSTRING message, IUnknown *language_exception)
306 FIXME("%#lx, %s, %p: stub\n", error, debugstr_hstring(message), language_exception);
307 return FALSE;
310 /***********************************************************************
311 * RoOriginateError (combase.@)
313 BOOL WINAPI RoOriginateError(HRESULT error, HSTRING message)
315 FIXME("%#lx, %s: stub\n", error, debugstr_hstring(message));
316 return FALSE;
319 /***********************************************************************
320 * RoSetErrorReportingFlags (combase.@)
322 HRESULT WINAPI RoSetErrorReportingFlags(UINT32 flags)
324 FIXME("(%08x): stub\n", flags);
325 return S_OK;
328 /***********************************************************************
329 * CleanupTlsOleState (combase.@)
331 void WINAPI CleanupTlsOleState(void *unknown)
333 FIXME("(%p): stub\n", unknown);
336 /***********************************************************************
337 * DllGetActivationFactory (combase.@)
339 HRESULT WINAPI DllGetActivationFactory(HSTRING classid, IActivationFactory **factory)
341 FIXME("(%s, %p): stub\n", debugstr_hstring(classid), factory);
343 return REGDB_E_CLASSNOTREG;