ucrtbase: Export _o_to{lower, upper}() as to{lower, upper}().
[wine.git] / dlls / combase / roapi.c
blob94b79ff3cfd7080fe0b32a9978aae0ec33f76264
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 static const WCHAR classkeyW[] = {'S','o','f','t','w','a','r','e','\\',
43 'M','i','c','r','o','s','o','f','t','\\',
44 'W','i','n','d','o','w','s','R','u','n','t','i','m','e','\\',
45 'A','c','t','i','v','a','t','a','b','l','e','C','l','a','s','s','I','d',0};
46 static const WCHAR dllpathW[] = {'D','l','l','P','a','t','h',0};
47 HKEY hkey_root, hkey_class;
48 DWORD type, size;
49 HRESULT hr;
50 WCHAR *buf = NULL;
52 *out = NULL;
54 /* load class registry key */
55 if (RegOpenKeyExW(HKEY_LOCAL_MACHINE, classkeyW, 0, KEY_READ, &hkey_root))
56 return REGDB_E_READREGDB;
57 if (RegOpenKeyExW(hkey_root, classid, 0, KEY_READ, &hkey_class))
59 WARN("Class %s not found in registry\n", debugstr_w(classid));
60 RegCloseKey(hkey_root);
61 return REGDB_E_CLASSNOTREG;
63 RegCloseKey(hkey_root);
65 /* load (and expand) DllPath registry value */
66 if (RegQueryValueExW(hkey_class, dllpathW, NULL, &type, NULL, &size))
68 hr = REGDB_E_READREGDB;
69 goto done;
71 if (type != REG_SZ && type != REG_EXPAND_SZ)
73 hr = REGDB_E_READREGDB;
74 goto done;
76 if (!(buf = HeapAlloc(GetProcessHeap(), 0, size)))
78 hr = E_OUTOFMEMORY;
79 goto done;
81 if (RegQueryValueExW(hkey_class, dllpathW, NULL, NULL, (BYTE *)buf, &size))
83 hr = REGDB_E_READREGDB;
84 goto done;
86 if (type == REG_EXPAND_SZ)
88 WCHAR *expanded;
89 DWORD len = ExpandEnvironmentStringsW(buf, NULL, 0);
90 if (!(expanded = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR))))
92 hr = E_OUTOFMEMORY;
93 goto done;
95 ExpandEnvironmentStringsW(buf, expanded, len);
96 HeapFree(GetProcessHeap(), 0, buf);
97 buf = expanded;
100 *out = buf;
101 return S_OK;
103 done:
104 HeapFree(GetProcessHeap(), 0, buf);
105 RegCloseKey(hkey_class);
106 return hr;
110 /***********************************************************************
111 * RoInitialize (combase.@)
113 HRESULT WINAPI RoInitialize(RO_INIT_TYPE type)
115 switch (type) {
116 case RO_INIT_SINGLETHREADED:
117 return CoInitializeEx(NULL, COINIT_APARTMENTTHREADED);
118 default:
119 FIXME("type %d\n", type);
120 case RO_INIT_MULTITHREADED:
121 return CoInitializeEx(NULL, COINIT_MULTITHREADED);
125 /***********************************************************************
126 * RoUninitialize (combase.@)
128 void WINAPI RoUninitialize(void)
130 CoUninitialize();
133 /***********************************************************************
134 * RoGetActivationFactory (combase.@)
136 HRESULT WINAPI RoGetActivationFactory(HSTRING classid, REFIID iid, void **class_factory)
138 PFNGETACTIVATIONFACTORY pDllGetActivationFactory;
139 IActivationFactory *factory;
140 WCHAR *library;
141 HMODULE module;
142 HRESULT hr;
144 FIXME("(%s, %s, %p): semi-stub\n", debugstr_hstring(classid), debugstr_guid(iid), class_factory);
146 if (!iid || !class_factory)
147 return E_INVALIDARG;
149 hr = get_library_for_classid(WindowsGetStringRawBuffer(classid, NULL), &library);
150 if (FAILED(hr))
152 ERR("Failed to find library for %s\n", debugstr_hstring(classid));
153 return hr;
156 if (!(module = LoadLibraryW(library)))
158 ERR("Failed to load module %s\n", debugstr_w(library));
159 hr = HRESULT_FROM_WIN32(GetLastError());
160 goto done;
163 if (!(pDllGetActivationFactory = (void *)GetProcAddress(module, "DllGetActivationFactory")))
165 ERR("Module %s does not implement DllGetActivationFactory\n", debugstr_w(library));
166 hr = E_FAIL;
167 goto done;
170 TRACE("Found library %s for class %s\n", debugstr_w(library), debugstr_hstring(classid));
172 hr = pDllGetActivationFactory(classid, &factory);
173 if (SUCCEEDED(hr))
175 hr = IActivationFactory_QueryInterface(factory, iid, class_factory);
176 if (SUCCEEDED(hr))
178 TRACE("Created interface %p\n", *class_factory);
179 module = NULL;
181 IActivationFactory_Release(factory);
184 done:
185 HeapFree(GetProcessHeap(), 0, library);
186 if (module) FreeLibrary(module);
187 return hr;
190 /***********************************************************************
191 * RoGetParameterizedTypeInstanceIID (combase.@)
193 HRESULT WINAPI RoGetParameterizedTypeInstanceIID(UINT32 name_element_count, const WCHAR **name_elements,
194 const IRoMetaDataLocator *meta_data_locator, GUID *iid,
195 ROPARAMIIDHANDLE *hiid)
197 FIXME("stub: %d %p %p %p %p\n", name_element_count, name_elements, meta_data_locator, iid, hiid);
198 if (iid) *iid = GUID_NULL;
199 if (hiid) *hiid = INVALID_HANDLE_VALUE;
200 return E_NOTIMPL;
203 /***********************************************************************
204 * RoActivateInstance (combase.@)
206 HRESULT WINAPI RoActivateInstance(HSTRING classid, IInspectable **instance)
208 IActivationFactory *factory;
209 HRESULT hr;
211 FIXME("(%p, %p): semi-stub\n", classid, instance);
213 hr = RoGetActivationFactory(classid, &IID_IActivationFactory, (void **)&factory);
214 if (SUCCEEDED(hr))
216 hr = IActivationFactory_ActivateInstance(factory, instance);
217 IActivationFactory_Release(factory);
220 return hr;
223 /***********************************************************************
224 * RoGetApartmentIdentifier (combase.@)
226 HRESULT WINAPI RoGetApartmentIdentifier(UINT64 *identifier)
228 FIXME("(%p): stub\n", identifier);
230 if (!identifier)
231 return E_INVALIDARG;
233 *identifier = 0xdeadbeef;
234 return S_OK;
237 /***********************************************************************
238 * RoRegisterForApartmentShutdown (combase.@)
240 HRESULT WINAPI RoRegisterForApartmentShutdown(IApartmentShutdown *callback,
241 UINT64 *identifier, APARTMENT_SHUTDOWN_REGISTRATION_COOKIE *cookie)
243 HRESULT hr;
245 FIXME("(%p, %p, %p): stub\n", callback, identifier, cookie);
247 hr = RoGetApartmentIdentifier(identifier);
248 if (FAILED(hr))
249 return hr;
251 if (cookie)
252 *cookie = (void *)0xcafecafe;
253 return S_OK;
256 /***********************************************************************
257 * RoGetServerActivatableClasses (combase.@)
259 HRESULT WINAPI RoGetServerActivatableClasses(HSTRING name, HSTRING **classes, DWORD *count)
261 FIXME("(%p, %p, %p): stub\n", name, classes, count);
263 if (count)
264 *count = 0;
265 return S_OK;
268 /***********************************************************************
269 * RoRegisterActivationFactories (combase.@)
271 HRESULT WINAPI RoRegisterActivationFactories(HSTRING *classes, PFNGETACTIVATIONFACTORY *callbacks,
272 UINT32 count, RO_REGISTRATION_COOKIE *cookie)
274 FIXME("(%p, %p, %d, %p): stub\n", classes, callbacks, count, cookie);
276 return S_OK;
279 /***********************************************************************
280 * GetRestrictedErrorInfo (combase.@)
282 HRESULT WINAPI GetRestrictedErrorInfo(IRestrictedErrorInfo **info)
284 FIXME( "(%p)\n", info );
285 return E_NOTIMPL;
288 /***********************************************************************
289 * RoOriginateLanguageException (combase.@)
291 BOOL WINAPI RoOriginateLanguageException(HRESULT error, HSTRING message, IUnknown *language_exception)
293 FIXME("(%x %s %p) stub\n", error, debugstr_hstring(message), language_exception);
294 return FALSE;
297 /***********************************************************************
298 * CleanupTlsOleState (combase.@)
300 void WINAPI CleanupTlsOleState(void *unknown)
302 FIXME("(%p): stub\n", unknown);
305 /***********************************************************************
306 * DllGetActivationFactory (combase.@)
308 HRESULT WINAPI DllGetActivationFactory(HSTRING classid, IActivationFactory **factory)
310 FIXME("(%s, %p): stub\n", debugstr_hstring(classid), factory);
312 return REGDB_E_CLASSNOTREG;