include/windows.foundation: Add double reference.
[wine.git] / dlls / combase / roapi.c
blobb80ca2e83255ecebba597646656e68d9b3ff1e95
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 struct activatable_class_data
33 ULONG size;
34 DWORD unk;
35 DWORD module_len;
36 DWORD module_offset;
37 DWORD threading_model;
40 static HRESULT get_library_for_classid(const WCHAR *classid, WCHAR **out)
42 ACTCTX_SECTION_KEYED_DATA data;
43 HKEY hkey_root, hkey_class;
44 DWORD type, size;
45 HRESULT hr;
46 WCHAR *buf = NULL;
48 *out = NULL;
50 /* search activation context first */
51 data.cbSize = sizeof(data);
52 if (FindActCtxSectionStringW(FIND_ACTCTX_SECTION_KEY_RETURN_HACTCTX, NULL,
53 ACTIVATION_CONTEXT_SECTION_WINRT_ACTIVATABLE_CLASSES, classid, &data))
55 struct activatable_class_data *activatable_class = (struct activatable_class_data *)data.lpData;
56 void *ptr = (BYTE *)data.lpSectionBase + activatable_class->module_offset;
57 *out = wcsdup(ptr);
58 return S_OK;
61 /* load class registry key */
62 if (RegOpenKeyExW(HKEY_LOCAL_MACHINE, L"Software\\Microsoft\\WindowsRuntime\\ActivatableClassId",
63 0, KEY_READ, &hkey_root))
64 return REGDB_E_READREGDB;
65 if (RegOpenKeyExW(hkey_root, classid, 0, KEY_READ, &hkey_class))
67 WARN("Class %s not found in registry\n", debugstr_w(classid));
68 RegCloseKey(hkey_root);
69 return REGDB_E_CLASSNOTREG;
71 RegCloseKey(hkey_root);
73 /* load (and expand) DllPath registry value */
74 if (RegQueryValueExW(hkey_class, L"DllPath", NULL, &type, NULL, &size))
76 hr = REGDB_E_READREGDB;
77 goto done;
79 if (type != REG_SZ && type != REG_EXPAND_SZ)
81 hr = REGDB_E_READREGDB;
82 goto done;
84 if (!(buf = malloc(size)))
86 hr = E_OUTOFMEMORY;
87 goto done;
89 if (RegQueryValueExW(hkey_class, L"DllPath", NULL, NULL, (BYTE *)buf, &size))
91 hr = REGDB_E_READREGDB;
92 goto done;
94 if (type == REG_EXPAND_SZ)
96 WCHAR *expanded;
97 DWORD len = ExpandEnvironmentStringsW(buf, NULL, 0);
98 if (!(expanded = malloc(len * sizeof(WCHAR))))
100 hr = E_OUTOFMEMORY;
101 goto done;
103 ExpandEnvironmentStringsW(buf, expanded, len);
104 free(buf);
105 buf = expanded;
108 *out = buf;
109 return S_OK;
111 done:
112 free(buf);
113 RegCloseKey(hkey_class);
114 return hr;
118 /***********************************************************************
119 * RoInitialize (combase.@)
121 HRESULT WINAPI RoInitialize(RO_INIT_TYPE type)
123 switch (type) {
124 case RO_INIT_SINGLETHREADED:
125 return CoInitializeEx(NULL, COINIT_APARTMENTTHREADED);
126 default:
127 FIXME("type %d\n", type);
128 case RO_INIT_MULTITHREADED:
129 return CoInitializeEx(NULL, COINIT_MULTITHREADED);
133 /***********************************************************************
134 * RoUninitialize (combase.@)
136 void WINAPI RoUninitialize(void)
138 CoUninitialize();
141 /***********************************************************************
142 * RoGetActivationFactory (combase.@)
144 HRESULT WINAPI RoGetActivationFactory(HSTRING classid, REFIID iid, void **class_factory)
146 PFNGETACTIVATIONFACTORY pDllGetActivationFactory;
147 IActivationFactory *factory;
148 WCHAR *library;
149 HMODULE module;
150 HRESULT hr;
152 FIXME("(%s, %s, %p): semi-stub\n", debugstr_hstring(classid), debugstr_guid(iid), class_factory);
154 if (!iid || !class_factory)
155 return E_INVALIDARG;
157 hr = get_library_for_classid(WindowsGetStringRawBuffer(classid, NULL), &library);
158 if (FAILED(hr))
160 ERR("Failed to find library for %s\n", debugstr_hstring(classid));
161 return hr;
164 if (!(module = LoadLibraryW(library)))
166 ERR("Failed to load module %s\n", debugstr_w(library));
167 hr = HRESULT_FROM_WIN32(GetLastError());
168 goto done;
171 if (!(pDllGetActivationFactory = (void *)GetProcAddress(module, "DllGetActivationFactory")))
173 ERR("Module %s does not implement DllGetActivationFactory\n", debugstr_w(library));
174 hr = E_FAIL;
175 goto done;
178 TRACE("Found library %s for class %s\n", debugstr_w(library), debugstr_hstring(classid));
180 hr = pDllGetActivationFactory(classid, &factory);
181 if (SUCCEEDED(hr))
183 hr = IActivationFactory_QueryInterface(factory, iid, class_factory);
184 if (SUCCEEDED(hr))
186 TRACE("Created interface %p\n", *class_factory);
187 module = NULL;
189 IActivationFactory_Release(factory);
192 done:
193 free(library);
194 if (module) FreeLibrary(module);
195 return hr;
198 /***********************************************************************
199 * RoGetParameterizedTypeInstanceIID (combase.@)
201 HRESULT WINAPI RoGetParameterizedTypeInstanceIID(UINT32 name_element_count, const WCHAR **name_elements,
202 const IRoMetaDataLocator *meta_data_locator, GUID *iid,
203 ROPARAMIIDHANDLE *hiid)
205 FIXME("stub: %d %p %p %p %p\n", name_element_count, name_elements, meta_data_locator, iid, hiid);
206 if (iid) *iid = GUID_NULL;
207 if (hiid) *hiid = INVALID_HANDLE_VALUE;
208 return E_NOTIMPL;
211 /***********************************************************************
212 * RoActivateInstance (combase.@)
214 HRESULT WINAPI RoActivateInstance(HSTRING classid, IInspectable **instance)
216 IActivationFactory *factory;
217 HRESULT hr;
219 FIXME("(%p, %p): semi-stub\n", classid, instance);
221 hr = RoGetActivationFactory(classid, &IID_IActivationFactory, (void **)&factory);
222 if (SUCCEEDED(hr))
224 hr = IActivationFactory_ActivateInstance(factory, instance);
225 IActivationFactory_Release(factory);
228 return hr;
231 /***********************************************************************
232 * RoGetApartmentIdentifier (combase.@)
234 HRESULT WINAPI RoGetApartmentIdentifier(UINT64 *identifier)
236 FIXME("(%p): stub\n", identifier);
238 if (!identifier)
239 return E_INVALIDARG;
241 *identifier = 0xdeadbeef;
242 return S_OK;
245 /***********************************************************************
246 * RoRegisterForApartmentShutdown (combase.@)
248 HRESULT WINAPI RoRegisterForApartmentShutdown(IApartmentShutdown *callback,
249 UINT64 *identifier, APARTMENT_SHUTDOWN_REGISTRATION_COOKIE *cookie)
251 HRESULT hr;
253 FIXME("(%p, %p, %p): stub\n", callback, identifier, cookie);
255 hr = RoGetApartmentIdentifier(identifier);
256 if (FAILED(hr))
257 return hr;
259 if (cookie)
260 *cookie = (void *)0xcafecafe;
261 return S_OK;
264 /***********************************************************************
265 * RoGetServerActivatableClasses (combase.@)
267 HRESULT WINAPI RoGetServerActivatableClasses(HSTRING name, HSTRING **classes, DWORD *count)
269 FIXME("(%p, %p, %p): stub\n", name, classes, count);
271 if (count)
272 *count = 0;
273 return S_OK;
276 /***********************************************************************
277 * RoRegisterActivationFactories (combase.@)
279 HRESULT WINAPI RoRegisterActivationFactories(HSTRING *classes, PFNGETACTIVATIONFACTORY *callbacks,
280 UINT32 count, RO_REGISTRATION_COOKIE *cookie)
282 FIXME("(%p, %p, %d, %p): stub\n", classes, callbacks, count, cookie);
284 return S_OK;
287 /***********************************************************************
288 * GetRestrictedErrorInfo (combase.@)
290 HRESULT WINAPI GetRestrictedErrorInfo(IRestrictedErrorInfo **info)
292 FIXME( "(%p)\n", info );
293 return E_NOTIMPL;
296 /***********************************************************************
297 * RoOriginateLanguageException (combase.@)
299 BOOL WINAPI RoOriginateLanguageException(HRESULT error, HSTRING message, IUnknown *language_exception)
301 FIXME("%#lx, %s, %p: stub\n", error, debugstr_hstring(message), language_exception);
302 return FALSE;
305 /***********************************************************************
306 * RoOriginateError (combase.@)
308 BOOL WINAPI RoOriginateError(HRESULT error, HSTRING message)
310 FIXME("%#lx, %s: stub\n", error, debugstr_hstring(message));
311 return FALSE;
314 /***********************************************************************
315 * RoSetErrorReportingFlags (combase.@)
317 HRESULT WINAPI RoSetErrorReportingFlags(UINT32 flags)
319 FIXME("(%08x): stub\n", flags);
320 return S_OK;
323 /***********************************************************************
324 * CleanupTlsOleState (combase.@)
326 void WINAPI CleanupTlsOleState(void *unknown)
328 FIXME("(%p): stub\n", unknown);
331 /***********************************************************************
332 * DllGetActivationFactory (combase.@)
334 HRESULT WINAPI DllGetActivationFactory(HSTRING classid, IActivationFactory **factory)
336 FIXME("(%s, %p): stub\n", debugstr_hstring(classid), factory);
338 return REGDB_E_CLASSNOTREG;