winspool: Change CUPS printers print processor to wineps.
[wine.git] / dlls / combase / roapi.c
blob78f35de39d4494ce50e8ca0aa46d4e9d4186fd04
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 struct activatable_class_data
42 ULONG size;
43 DWORD unk;
44 DWORD module_len;
45 DWORD module_offset;
46 DWORD threading_model;
49 static HRESULT get_library_for_classid(const WCHAR *classid, WCHAR **out)
51 ACTCTX_SECTION_KEYED_DATA data;
52 HKEY hkey_root, hkey_class;
53 DWORD type, size;
54 HRESULT hr;
55 WCHAR *buf = NULL;
57 *out = NULL;
59 /* search activation context first */
60 data.cbSize = sizeof(data);
61 if (FindActCtxSectionStringW(FIND_ACTCTX_SECTION_KEY_RETURN_HACTCTX, NULL,
62 ACTIVATION_CONTEXT_SECTION_WINRT_ACTIVATABLE_CLASSES, classid, &data))
64 struct activatable_class_data *activatable_class = (struct activatable_class_data *)data.lpData;
65 void *ptr = (BYTE *)data.lpSectionBase + activatable_class->module_offset;
66 *out = wcsdup(ptr);
67 return S_OK;
70 /* load class registry key */
71 if (RegOpenKeyExW(HKEY_LOCAL_MACHINE, L"Software\\Microsoft\\WindowsRuntime\\ActivatableClassId",
72 0, KEY_READ, &hkey_root))
73 return REGDB_E_READREGDB;
74 if (RegOpenKeyExW(hkey_root, classid, 0, KEY_READ, &hkey_class))
76 WARN("Class %s not found in registry\n", debugstr_w(classid));
77 RegCloseKey(hkey_root);
78 return REGDB_E_CLASSNOTREG;
80 RegCloseKey(hkey_root);
82 /* load (and expand) DllPath registry value */
83 if (RegQueryValueExW(hkey_class, L"DllPath", NULL, &type, NULL, &size))
85 hr = REGDB_E_READREGDB;
86 goto done;
88 if (type != REG_SZ && type != REG_EXPAND_SZ)
90 hr = REGDB_E_READREGDB;
91 goto done;
93 if (!(buf = malloc(size)))
95 hr = E_OUTOFMEMORY;
96 goto done;
98 if (RegQueryValueExW(hkey_class, L"DllPath", NULL, NULL, (BYTE *)buf, &size))
100 hr = REGDB_E_READREGDB;
101 goto done;
103 if (type == REG_EXPAND_SZ)
105 WCHAR *expanded;
106 DWORD len = ExpandEnvironmentStringsW(buf, NULL, 0);
107 if (!(expanded = malloc(len * sizeof(WCHAR))))
109 hr = E_OUTOFMEMORY;
110 goto done;
112 ExpandEnvironmentStringsW(buf, expanded, len);
113 free(buf);
114 buf = expanded;
117 *out = buf;
118 return S_OK;
120 done:
121 free(buf);
122 RegCloseKey(hkey_class);
123 return hr;
127 /***********************************************************************
128 * RoInitialize (combase.@)
130 HRESULT WINAPI RoInitialize(RO_INIT_TYPE type)
132 switch (type) {
133 case RO_INIT_SINGLETHREADED:
134 return CoInitializeEx(NULL, COINIT_APARTMENTTHREADED);
135 default:
136 FIXME("type %d\n", type);
137 case RO_INIT_MULTITHREADED:
138 return CoInitializeEx(NULL, COINIT_MULTITHREADED);
142 /***********************************************************************
143 * RoUninitialize (combase.@)
145 void WINAPI RoUninitialize(void)
147 CoUninitialize();
150 /***********************************************************************
151 * RoGetActivationFactory (combase.@)
153 HRESULT WINAPI RoGetActivationFactory(HSTRING classid, REFIID iid, void **class_factory)
155 PFNGETACTIVATIONFACTORY pDllGetActivationFactory;
156 IActivationFactory *factory;
157 WCHAR *library;
158 HMODULE module;
159 HRESULT hr;
161 FIXME("(%s, %s, %p): semi-stub\n", debugstr_hstring(classid), debugstr_guid(iid), class_factory);
163 if (!iid || !class_factory)
164 return E_INVALIDARG;
166 hr = get_library_for_classid(WindowsGetStringRawBuffer(classid, NULL), &library);
167 if (FAILED(hr))
169 ERR("Failed to find library for %s\n", debugstr_hstring(classid));
170 return hr;
173 if (!(module = LoadLibraryW(library)))
175 ERR("Failed to load module %s\n", debugstr_w(library));
176 hr = HRESULT_FROM_WIN32(GetLastError());
177 goto done;
180 if (!(pDllGetActivationFactory = (void *)GetProcAddress(module, "DllGetActivationFactory")))
182 ERR("Module %s does not implement DllGetActivationFactory\n", debugstr_w(library));
183 hr = E_FAIL;
184 goto done;
187 TRACE("Found library %s for class %s\n", debugstr_w(library), debugstr_hstring(classid));
189 hr = pDllGetActivationFactory(classid, &factory);
190 if (SUCCEEDED(hr))
192 hr = IActivationFactory_QueryInterface(factory, iid, class_factory);
193 if (SUCCEEDED(hr))
195 TRACE("Created interface %p\n", *class_factory);
196 module = NULL;
198 IActivationFactory_Release(factory);
201 done:
202 free(library);
203 if (module) FreeLibrary(module);
204 return hr;
207 /***********************************************************************
208 * RoGetParameterizedTypeInstanceIID (combase.@)
210 HRESULT WINAPI RoGetParameterizedTypeInstanceIID(UINT32 name_element_count, const WCHAR **name_elements,
211 const IRoMetaDataLocator *meta_data_locator, GUID *iid,
212 ROPARAMIIDHANDLE *hiid)
214 FIXME("stub: %d %p %p %p %p\n", name_element_count, name_elements, meta_data_locator, iid, hiid);
215 if (iid) *iid = GUID_NULL;
216 if (hiid) *hiid = INVALID_HANDLE_VALUE;
217 return E_NOTIMPL;
220 /***********************************************************************
221 * RoActivateInstance (combase.@)
223 HRESULT WINAPI RoActivateInstance(HSTRING classid, IInspectable **instance)
225 IActivationFactory *factory;
226 HRESULT hr;
228 FIXME("(%p, %p): semi-stub\n", classid, instance);
230 hr = RoGetActivationFactory(classid, &IID_IActivationFactory, (void **)&factory);
231 if (SUCCEEDED(hr))
233 hr = IActivationFactory_ActivateInstance(factory, instance);
234 IActivationFactory_Release(factory);
237 return hr;
240 /***********************************************************************
241 * RoGetApartmentIdentifier (combase.@)
243 HRESULT WINAPI RoGetApartmentIdentifier(UINT64 *identifier)
245 FIXME("(%p): stub\n", identifier);
247 if (!identifier)
248 return E_INVALIDARG;
250 *identifier = 0xdeadbeef;
251 return S_OK;
254 /***********************************************************************
255 * RoRegisterForApartmentShutdown (combase.@)
257 HRESULT WINAPI RoRegisterForApartmentShutdown(IApartmentShutdown *callback,
258 UINT64 *identifier, APARTMENT_SHUTDOWN_REGISTRATION_COOKIE *cookie)
260 HRESULT hr;
262 FIXME("(%p, %p, %p): stub\n", callback, identifier, cookie);
264 hr = RoGetApartmentIdentifier(identifier);
265 if (FAILED(hr))
266 return hr;
268 if (cookie)
269 *cookie = (void *)0xcafecafe;
270 return S_OK;
273 /***********************************************************************
274 * RoGetServerActivatableClasses (combase.@)
276 HRESULT WINAPI RoGetServerActivatableClasses(HSTRING name, HSTRING **classes, DWORD *count)
278 FIXME("(%p, %p, %p): stub\n", name, classes, count);
280 if (count)
281 *count = 0;
282 return S_OK;
285 /***********************************************************************
286 * RoRegisterActivationFactories (combase.@)
288 HRESULT WINAPI RoRegisterActivationFactories(HSTRING *classes, PFNGETACTIVATIONFACTORY *callbacks,
289 UINT32 count, RO_REGISTRATION_COOKIE *cookie)
291 FIXME("(%p, %p, %d, %p): stub\n", classes, callbacks, count, cookie);
293 return S_OK;
296 /***********************************************************************
297 * GetRestrictedErrorInfo (combase.@)
299 HRESULT WINAPI GetRestrictedErrorInfo(IRestrictedErrorInfo **info)
301 FIXME( "(%p)\n", info );
302 return E_NOTIMPL;
305 /***********************************************************************
306 * RoOriginateLanguageException (combase.@)
308 BOOL WINAPI RoOriginateLanguageException(HRESULT error, HSTRING message, IUnknown *language_exception)
310 FIXME("%#lx, %s, %p: stub\n", error, debugstr_hstring(message), language_exception);
311 return FALSE;
314 /***********************************************************************
315 * RoOriginateError (combase.@)
317 BOOL WINAPI RoOriginateError(HRESULT error, HSTRING message)
319 FIXME("%#lx, %s: stub\n", error, debugstr_hstring(message));
320 return FALSE;
323 /***********************************************************************
324 * RoSetErrorReportingFlags (combase.@)
326 HRESULT WINAPI RoSetErrorReportingFlags(UINT32 flags)
328 FIXME("(%08x): stub\n", flags);
329 return S_OK;
332 /***********************************************************************
333 * CleanupTlsOleState (combase.@)
335 void WINAPI CleanupTlsOleState(void *unknown)
337 FIXME("(%p): stub\n", unknown);
340 /***********************************************************************
341 * DllGetActivationFactory (combase.@)
343 HRESULT WINAPI DllGetActivationFactory(HSTRING classid, IActivationFactory **factory)
345 FIXME("(%s, %p): stub\n", debugstr_hstring(classid), factory);
347 return REGDB_E_CLASSNOTREG;