1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294
|
/*
* Copyright 2014 Martin Storsjo
* Copyright 2016 Michael Müller
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
*/
#define COBJMACROS
#include "objbase.h"
#include "initguid.h"
#include "roapi.h"
#include "roparameterizediid.h"
#include "winstring.h"
#include "wine/debug.h"
WINE_DEFAULT_DEBUG_CHANNEL(combase);
static const char *debugstr_hstring(HSTRING hstr)
{
const WCHAR *str;
UINT32 len;
if (hstr && !((ULONG_PTR)hstr >> 16)) return "(invalid)";
str = WindowsGetStringRawBuffer(hstr, &len);
return wine_dbgstr_wn(str, len);
}
static HRESULT get_library_for_classid(const WCHAR *classid, WCHAR **out)
{
static const WCHAR classkeyW[] = {'S','o','f','t','w','a','r','e','\\',
'M','i','c','r','o','s','o','f','t','\\',
'W','i','n','d','o','w','s','R','u','n','t','i','m','e','\\',
'A','c','t','i','v','a','t','a','b','l','e','C','l','a','s','s','I','d',0};
static const WCHAR dllpathW[] = {'D','l','l','P','a','t','h',0};
HKEY hkey_root, hkey_class;
DWORD type, size;
HRESULT hr;
WCHAR *buf = NULL;
*out = NULL;
/* load class registry key */
if (RegOpenKeyExW(HKEY_LOCAL_MACHINE, classkeyW, 0, KEY_READ, &hkey_root))
return REGDB_E_READREGDB;
if (RegOpenKeyExW(hkey_root, classid, 0, KEY_READ, &hkey_class))
{
WARN("Class %s not found in registry\n", debugstr_w(classid));
RegCloseKey(hkey_root);
return REGDB_E_CLASSNOTREG;
}
RegCloseKey(hkey_root);
/* load (and expand) DllPath registry value */
if (RegQueryValueExW(hkey_class, dllpathW, NULL, &type, NULL, &size))
{
hr = REGDB_E_READREGDB;
goto done;
}
if (type != REG_SZ && type != REG_EXPAND_SZ)
{
hr = REGDB_E_READREGDB;
goto done;
}
if (!(buf = HeapAlloc(GetProcessHeap(), 0, size)))
{
hr = E_OUTOFMEMORY;
goto done;
}
if (RegQueryValueExW(hkey_class, dllpathW, NULL, NULL, (BYTE *)buf, &size))
{
hr = REGDB_E_READREGDB;
goto done;
}
if (type == REG_EXPAND_SZ)
{
WCHAR *expanded;
DWORD len = ExpandEnvironmentStringsW(buf, NULL, 0);
if (!(expanded = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR))))
{
hr = E_OUTOFMEMORY;
goto done;
}
ExpandEnvironmentStringsW(buf, expanded, len);
HeapFree(GetProcessHeap(), 0, buf);
buf = expanded;
}
*out = buf;
return S_OK;
done:
HeapFree(GetProcessHeap(), 0, buf);
RegCloseKey(hkey_class);
return hr;
}
/***********************************************************************
* RoInitialize (combase.@)
*/
HRESULT WINAPI RoInitialize(RO_INIT_TYPE type)
{
switch (type) {
case RO_INIT_SINGLETHREADED:
return CoInitializeEx(NULL, COINIT_APARTMENTTHREADED);
default:
FIXME("type %d\n", type);
case RO_INIT_MULTITHREADED:
return CoInitializeEx(NULL, COINIT_MULTITHREADED);
}
}
/***********************************************************************
* RoUninitialize (combase.@)
*/
void WINAPI RoUninitialize(void)
{
CoUninitialize();
}
/***********************************************************************
* RoGetActivationFactory (combase.@)
*/
HRESULT WINAPI RoGetActivationFactory(HSTRING classid, REFIID iid, void **class_factory)
{
PFNGETACTIVATIONFACTORY pDllGetActivationFactory;
IActivationFactory *factory;
WCHAR *library;
HMODULE module;
HRESULT hr;
FIXME("(%s, %s, %p): semi-stub\n", debugstr_hstring(classid), debugstr_guid(iid), class_factory);
if (!iid || !class_factory)
return E_INVALIDARG;
hr = get_library_for_classid(WindowsGetStringRawBuffer(classid, NULL), &library);
if (FAILED(hr))
{
ERR("Failed to find library for %s\n", debugstr_hstring(classid));
return hr;
}
if (!(module = LoadLibraryW(library)))
{
ERR("Failed to load module %s\n", debugstr_w(library));
hr = HRESULT_FROM_WIN32(GetLastError());
goto done;
}
if (!(pDllGetActivationFactory = (void *)GetProcAddress(module, "DllGetActivationFactory")))
{
ERR("Module %s does not implement DllGetActivationFactory\n", debugstr_w(library));
hr = E_FAIL;
goto done;
}
TRACE("Found library %s for class %s\n", debugstr_w(library), debugstr_hstring(classid));
hr = pDllGetActivationFactory(classid, &factory);
if (SUCCEEDED(hr))
{
hr = IActivationFactory_QueryInterface(factory, iid, class_factory);
if (SUCCEEDED(hr))
{
TRACE("Created interface %p\n", *class_factory);
module = NULL;
}
IActivationFactory_Release(factory);
}
done:
HeapFree(GetProcessHeap(), 0, library);
if (module) FreeLibrary(module);
return hr;
}
/***********************************************************************
* RoGetParameterizedTypeInstanceIID (combase.@)
*/
HRESULT WINAPI RoGetParameterizedTypeInstanceIID(UINT32 name_element_count, const WCHAR **name_elements,
const IRoMetaDataLocator *meta_data_locator, GUID *iid,
ROPARAMIIDHANDLE *hiid)
{
FIXME("stub: %d %p %p %p %p\n", name_element_count, name_elements, meta_data_locator, iid, hiid);
if (iid) *iid = GUID_NULL;
if (hiid) *hiid = INVALID_HANDLE_VALUE;
return E_NOTIMPL;
}
/***********************************************************************
* RoActivateInstance (combase.@)
*/
HRESULT WINAPI RoActivateInstance(HSTRING classid, IInspectable **instance)
{
IActivationFactory *factory;
HRESULT hr;
FIXME("(%p, %p): semi-stub\n", classid, instance);
hr = RoGetActivationFactory(classid, &IID_IActivationFactory, (void **)&factory);
if (SUCCEEDED(hr))
{
hr = IActivationFactory_ActivateInstance(factory, instance);
IActivationFactory_Release(factory);
}
return hr;
}
/***********************************************************************
* RoGetApartmentIdentifier (combase.@)
*/
HRESULT WINAPI RoGetApartmentIdentifier(UINT64 *identifier)
{
FIXME("(%p): stub\n", identifier);
if (!identifier)
return E_INVALIDARG;
*identifier = 0xdeadbeef;
return S_OK;
}
/***********************************************************************
* RoRegisterForApartmentShutdown (combase.@)
*/
HRESULT WINAPI RoRegisterForApartmentShutdown(IApartmentShutdown *callback,
UINT64 *identifier, APARTMENT_SHUTDOWN_REGISTRATION_COOKIE *cookie)
{
HRESULT hr;
FIXME("(%p, %p, %p): stub\n", callback, identifier, cookie);
hr = RoGetApartmentIdentifier(identifier);
if (FAILED(hr))
return hr;
if (cookie)
*cookie = (void *)0xcafecafe;
return S_OK;
}
/***********************************************************************
* RoGetServerActivatableClasses (combase.@)
*/
HRESULT WINAPI RoGetServerActivatableClasses(HSTRING name, HSTRING **classes, DWORD *count)
{
FIXME("(%p, %p, %p): stub\n", name, classes, count);
if (count)
*count = 0;
return S_OK;
}
/***********************************************************************
* RoRegisterActivationFactories (combase.@)
*/
HRESULT WINAPI RoRegisterActivationFactories(HSTRING *classes, PFNGETACTIVATIONFACTORY *callbacks,
UINT32 count, RO_REGISTRATION_COOKIE *cookie)
{
FIXME("(%p, %p, %d, %p): stub\n", classes, callbacks, count, cookie);
return S_OK;
}
/***********************************************************************
* CleanupTlsOleState (combase.@)
*/
void WINAPI CleanupTlsOleState(void *unknown)
{
FIXME("(%p): stub\n", unknown);
}
/***********************************************************************
* DllGetActivationFactory (combase.@)
*/
HRESULT WINAPI DllGetActivationFactory(HSTRING classid, IActivationFactory **factory)
{
FIXME("(%s, %p): stub\n", debugstr_hstring(classid), factory);
return REGDB_E_CLASSNOTREG;
}
|