combase: Add stub for RoGetServerActivatableClasses.
[wine.git] / dlls / combase / roapi.c
blob96165e4dbedf6411b4870230e3f32803041ab649
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 "winstring.h"
26 #include "wine/debug.h"
28 WINE_DEFAULT_DEBUG_CHANNEL(combase);
30 static const char *debugstr_hstring(HSTRING hstr)
32 const WCHAR *str;
33 UINT32 len;
34 if (hstr && !((ULONG_PTR)hstr >> 16)) return "(invalid)";
35 str = WindowsGetStringRawBuffer(hstr, &len);
36 return wine_dbgstr_wn(str, len);
39 static HRESULT get_library_for_classid(const WCHAR *classid, WCHAR **out)
41 static const WCHAR classkeyW[] = {'S','o','f','t','w','a','r','e','\\',
42 'M','i','c','r','o','s','o','f','t','\\',
43 'W','i','n','d','o','w','s','R','u','n','t','i','m','e','\\',
44 'A','c','t','i','v','a','t','a','b','l','e','C','l','a','s','s','I','d',0};
45 static const WCHAR dllpathW[] = {'D','l','l','P','a','t','h',0};
46 HKEY hkey_root, hkey_class;
47 DWORD type, size;
48 HRESULT hr;
49 WCHAR *buf = NULL;
51 *out = NULL;
53 /* load class registry key */
54 if (RegOpenKeyExW(HKEY_LOCAL_MACHINE, classkeyW, 0, KEY_READ, &hkey_root))
55 return REGDB_E_READREGDB;
56 if (RegOpenKeyExW(hkey_root, classid, 0, KEY_READ, &hkey_class))
58 WARN("Class %s not found in registry\n", debugstr_w(classid));
59 RegCloseKey(hkey_root);
60 return REGDB_E_CLASSNOTREG;
62 RegCloseKey(hkey_root);
64 /* load (and expand) DllPath registry value */
65 if (RegQueryValueExW(hkey_class, dllpathW, NULL, &type, NULL, &size))
67 hr = REGDB_E_READREGDB;
68 goto done;
70 if (type != REG_SZ && type != REG_EXPAND_SZ)
72 hr = REGDB_E_READREGDB;
73 goto done;
75 if (!(buf = HeapAlloc(GetProcessHeap(), 0, size)))
77 hr = E_OUTOFMEMORY;
78 goto done;
80 if (RegQueryValueExW(hkey_class, dllpathW, NULL, NULL, (BYTE *)buf, &size))
82 hr = REGDB_E_READREGDB;
83 goto done;
85 if (type == REG_EXPAND_SZ)
87 WCHAR *expanded;
88 DWORD len = ExpandEnvironmentStringsW(buf, NULL, 0);
89 if (!(expanded = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR))))
91 hr = E_OUTOFMEMORY;
92 goto done;
94 ExpandEnvironmentStringsW(buf, expanded, len);
95 HeapFree(GetProcessHeap(), 0, buf);
96 buf = expanded;
99 *out = buf;
100 return S_OK;
102 done:
103 HeapFree(GetProcessHeap(), 0, buf);
104 RegCloseKey(hkey_class);
105 return hr;
109 /***********************************************************************
110 * RoInitialize (combase.@)
112 HRESULT WINAPI RoInitialize(RO_INIT_TYPE type)
114 switch (type) {
115 case RO_INIT_SINGLETHREADED:
116 return CoInitializeEx(NULL, COINIT_APARTMENTTHREADED);
117 default:
118 FIXME("type %d\n", type);
119 case RO_INIT_MULTITHREADED:
120 return CoInitializeEx(NULL, COINIT_MULTITHREADED);
124 /***********************************************************************
125 * RoUninitialize (combase.@)
127 void WINAPI RoUninitialize(void)
129 CoUninitialize();
132 /***********************************************************************
133 * RoGetActivationFactory (combase.@)
135 HRESULT WINAPI RoGetActivationFactory(HSTRING classid, REFIID iid, void **class_factory)
137 PFNGETACTIVATIONFACTORY pDllGetActivationFactory;
138 IActivationFactory *factory;
139 WCHAR *library;
140 HMODULE module;
141 HRESULT hr;
143 FIXME("(%s, %s, %p): semi-stub\n", debugstr_hstring(classid), debugstr_guid(iid), class_factory);
145 if (!iid || !class_factory)
146 return E_INVALIDARG;
148 hr = get_library_for_classid(WindowsGetStringRawBuffer(classid, NULL), &library);
149 if (FAILED(hr))
151 ERR("Failed to find library for %s\n", debugstr_hstring(classid));
152 return hr;
155 if (!(module = LoadLibraryW(library)))
157 ERR("Failed to load module %s\n", debugstr_w(library));
158 hr = HRESULT_FROM_WIN32(GetLastError());
159 goto done;
162 if (!(pDllGetActivationFactory = (void *)GetProcAddress(module, "DllGetActivationFactory")))
164 ERR("Module %s does not implement DllGetActivationFactory\n", debugstr_w(library));
165 hr = E_FAIL;
166 goto done;
169 TRACE("Found library %s for class %s\n", debugstr_w(library), debugstr_hstring(classid));
171 hr = pDllGetActivationFactory(classid, &factory);
172 if (SUCCEEDED(hr))
174 hr = IActivationFactory_QueryInterface(factory, iid, class_factory);
175 if (SUCCEEDED(hr))
177 TRACE("Created interface %p\n", *class_factory);
178 module = NULL;
180 IActivationFactory_Release(factory);
183 done:
184 HeapFree(GetProcessHeap(), 0, library);
185 if (module) FreeLibrary(module);
186 return hr;
189 /***********************************************************************
190 * RoGetParameterizedTypeInstanceIID (combase.@)
192 HRESULT WINAPI RoGetParameterizedTypeInstanceIID(UINT32 name_element_count, const WCHAR **name_elements,
193 const IRoMetaDataLocator *meta_data_locator, GUID *iid,
194 ROPARAMIIDHANDLE *hiid)
196 FIXME("stub: %d %p %p %p %p\n", name_element_count, name_elements, meta_data_locator, iid, hiid);
197 if (iid) *iid = GUID_NULL;
198 if (hiid) *hiid = INVALID_HANDLE_VALUE;
199 return E_NOTIMPL;
202 /***********************************************************************
203 * RoActivateInstance (combase.@)
205 HRESULT WINAPI RoActivateInstance(HSTRING classid, IInspectable **instance)
207 IActivationFactory *factory;
208 HRESULT hr;
210 FIXME("(%p, %p): semi-stub\n", classid, instance);
212 hr = RoGetActivationFactory(classid, &IID_IActivationFactory, (void **)&factory);
213 if (SUCCEEDED(hr))
215 hr = IActivationFactory_ActivateInstance(factory, instance);
216 IActivationFactory_Release(factory);
219 return hr;
222 /***********************************************************************
223 * RoGetApartmentIdentifier (combase.@)
225 HRESULT WINAPI RoGetApartmentIdentifier(UINT64 *identifier)
227 FIXME("(%p): stub\n", identifier);
229 if (!identifier)
230 return E_INVALIDARG;
232 *identifier = 0xdeadbeef;
233 return S_OK;
236 /***********************************************************************
237 * RoRegisterForApartmentShutdown (combase.@)
239 HRESULT WINAPI RoRegisterForApartmentShutdown(IApartmentShutdown *callback,
240 UINT64 *identifier, APARTMENT_SHUTDOWN_REGISTRATION_COOKIE *cookie)
242 HRESULT hr;
244 FIXME("(%p, %p, %p): stub\n", callback, identifier, cookie);
246 hr = RoGetApartmentIdentifier(identifier);
247 if (FAILED(hr))
248 return hr;
250 if (cookie)
251 *cookie = (void *)0xcafecafe;
252 return S_OK;
255 /***********************************************************************
256 * RoGetServerActivatableClasses (combase.@)
258 HRESULT WINAPI RoGetServerActivatableClasses(HSTRING name, HSTRING **classes, DWORD *count)
260 FIXME("(%p, %p, %p): stub\n", name, classes, count);
262 if (count)
263 *count = 0;
264 return S_OK;