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
23 #include "roparameterizediid.h"
24 #include "roerrorapi.h"
25 #include "winstring.h"
27 #include "combase_private.h"
29 #include "wine/debug.h"
31 WINE_DEFAULT_DEBUG_CHANNEL(combase
);
33 struct activatable_class_data
39 DWORD threading_model
;
42 static HRESULT
get_library_for_classid(const WCHAR
*classid
, WCHAR
**out
)
44 ACTCTX_SECTION_KEYED_DATA data
;
45 HKEY hkey_root
, hkey_class
;
52 /* search activation context first */
53 data
.cbSize
= sizeof(data
);
54 if (FindActCtxSectionStringW(FIND_ACTCTX_SECTION_KEY_RETURN_HACTCTX
, NULL
,
55 ACTIVATION_CONTEXT_SECTION_WINRT_ACTIVATABLE_CLASSES
, classid
, &data
))
57 struct activatable_class_data
*activatable_class
= (struct activatable_class_data
*)data
.lpData
;
58 void *ptr
= (BYTE
*)data
.lpSectionBase
+ activatable_class
->module_offset
;
63 /* load class registry key */
64 if (RegOpenKeyExW(HKEY_LOCAL_MACHINE
, L
"Software\\Microsoft\\WindowsRuntime\\ActivatableClassId",
65 0, KEY_READ
, &hkey_root
))
66 return REGDB_E_READREGDB
;
67 if (RegOpenKeyExW(hkey_root
, classid
, 0, KEY_READ
, &hkey_class
))
69 WARN("Class %s not found in registry\n", debugstr_w(classid
));
70 RegCloseKey(hkey_root
);
71 return REGDB_E_CLASSNOTREG
;
73 RegCloseKey(hkey_root
);
75 /* load (and expand) DllPath registry value */
76 if (RegQueryValueExW(hkey_class
, L
"DllPath", NULL
, &type
, NULL
, &size
))
78 hr
= REGDB_E_READREGDB
;
81 if (type
!= REG_SZ
&& type
!= REG_EXPAND_SZ
)
83 hr
= REGDB_E_READREGDB
;
86 if (!(buf
= malloc(size
)))
91 if (RegQueryValueExW(hkey_class
, L
"DllPath", NULL
, NULL
, (BYTE
*)buf
, &size
))
93 hr
= REGDB_E_READREGDB
;
96 if (type
== REG_EXPAND_SZ
)
99 DWORD len
= ExpandEnvironmentStringsW(buf
, NULL
, 0);
100 if (!(expanded
= malloc(len
* sizeof(WCHAR
))))
105 ExpandEnvironmentStringsW(buf
, expanded
, len
);
115 RegCloseKey(hkey_class
);
120 /***********************************************************************
121 * RoInitialize (combase.@)
123 HRESULT WINAPI
RoInitialize(RO_INIT_TYPE type
)
126 case RO_INIT_SINGLETHREADED
:
127 return CoInitializeEx(NULL
, COINIT_APARTMENTTHREADED
);
129 FIXME("type %d\n", type
);
130 case RO_INIT_MULTITHREADED
:
131 return CoInitializeEx(NULL
, COINIT_MULTITHREADED
);
135 /***********************************************************************
136 * RoUninitialize (combase.@)
138 void WINAPI
RoUninitialize(void)
143 /***********************************************************************
144 * RoGetActivationFactory (combase.@)
146 HRESULT WINAPI DECLSPEC_HOTPATCH
RoGetActivationFactory(HSTRING classid
, REFIID iid
, void **class_factory
)
148 PFNGETACTIVATIONFACTORY pDllGetActivationFactory
;
149 IActivationFactory
*factory
;
154 FIXME("(%s, %s, %p): semi-stub\n", debugstr_hstring(classid
), debugstr_guid(iid
), class_factory
);
156 if (!iid
|| !class_factory
)
159 if (FAILED(hr
= ensure_mta()))
162 hr
= get_library_for_classid(WindowsGetStringRawBuffer(classid
, NULL
), &library
);
165 ERR("Failed to find library for %s\n", debugstr_hstring(classid
));
169 if (!(module
= LoadLibraryW(library
)))
171 ERR("Failed to load module %s\n", debugstr_w(library
));
172 hr
= HRESULT_FROM_WIN32(GetLastError());
176 if (!(pDllGetActivationFactory
= (void *)GetProcAddress(module
, "DllGetActivationFactory")))
178 ERR("Module %s does not implement DllGetActivationFactory\n", debugstr_w(library
));
183 TRACE("Found library %s for class %s\n", debugstr_w(library
), debugstr_hstring(classid
));
185 hr
= pDllGetActivationFactory(classid
, &factory
);
188 hr
= IActivationFactory_QueryInterface(factory
, iid
, class_factory
);
191 TRACE("Created interface %p\n", *class_factory
);
194 IActivationFactory_Release(factory
);
199 if (module
) FreeLibrary(module
);
203 /***********************************************************************
204 * RoGetParameterizedTypeInstanceIID (combase.@)
206 HRESULT WINAPI
RoGetParameterizedTypeInstanceIID(UINT32 name_element_count
, const WCHAR
**name_elements
,
207 const IRoMetaDataLocator
*meta_data_locator
, GUID
*iid
,
208 ROPARAMIIDHANDLE
*hiid
)
210 FIXME("stub: %d %p %p %p %p\n", name_element_count
, name_elements
, meta_data_locator
, iid
, hiid
);
211 if (iid
) *iid
= GUID_NULL
;
212 if (hiid
) *hiid
= INVALID_HANDLE_VALUE
;
216 /***********************************************************************
217 * RoActivateInstance (combase.@)
219 HRESULT WINAPI
RoActivateInstance(HSTRING classid
, IInspectable
**instance
)
221 IActivationFactory
*factory
;
224 FIXME("(%p, %p): semi-stub\n", classid
, instance
);
226 hr
= RoGetActivationFactory(classid
, &IID_IActivationFactory
, (void **)&factory
);
229 hr
= IActivationFactory_ActivateInstance(factory
, instance
);
230 IActivationFactory_Release(factory
);
236 /***********************************************************************
237 * RoGetApartmentIdentifier (combase.@)
239 HRESULT WINAPI
RoGetApartmentIdentifier(UINT64
*identifier
)
241 FIXME("(%p): stub\n", identifier
);
246 *identifier
= 0xdeadbeef;
250 /***********************************************************************
251 * RoRegisterForApartmentShutdown (combase.@)
253 HRESULT WINAPI
RoRegisterForApartmentShutdown(IApartmentShutdown
*callback
,
254 UINT64
*identifier
, APARTMENT_SHUTDOWN_REGISTRATION_COOKIE
*cookie
)
258 FIXME("(%p, %p, %p): stub\n", callback
, identifier
, cookie
);
260 hr
= RoGetApartmentIdentifier(identifier
);
265 *cookie
= (void *)0xcafecafe;
269 /***********************************************************************
270 * RoGetServerActivatableClasses (combase.@)
272 HRESULT WINAPI
RoGetServerActivatableClasses(HSTRING name
, HSTRING
**classes
, DWORD
*count
)
274 FIXME("(%p, %p, %p): stub\n", name
, classes
, count
);
281 /***********************************************************************
282 * RoRegisterActivationFactories (combase.@)
284 HRESULT WINAPI
RoRegisterActivationFactories(HSTRING
*classes
, PFNGETACTIVATIONFACTORY
*callbacks
,
285 UINT32 count
, RO_REGISTRATION_COOKIE
*cookie
)
287 FIXME("(%p, %p, %d, %p): stub\n", classes
, callbacks
, count
, cookie
);
292 /***********************************************************************
293 * GetRestrictedErrorInfo (combase.@)
295 HRESULT WINAPI
GetRestrictedErrorInfo(IRestrictedErrorInfo
**info
)
297 FIXME( "(%p)\n", info
);
301 /***********************************************************************
302 * RoOriginateLanguageException (combase.@)
304 BOOL WINAPI
RoOriginateLanguageException(HRESULT error
, HSTRING message
, IUnknown
*language_exception
)
306 FIXME("%#lx, %s, %p: stub\n", error
, debugstr_hstring(message
), language_exception
);
310 /***********************************************************************
311 * RoOriginateError (combase.@)
313 BOOL WINAPI
RoOriginateError(HRESULT error
, HSTRING message
)
315 FIXME("%#lx, %s: stub\n", error
, debugstr_hstring(message
));
319 /***********************************************************************
320 * RoSetErrorReportingFlags (combase.@)
322 HRESULT WINAPI
RoSetErrorReportingFlags(UINT32 flags
)
324 FIXME("(%08x): stub\n", flags
);
328 /***********************************************************************
329 * CleanupTlsOleState (combase.@)
331 void WINAPI
CleanupTlsOleState(void *unknown
)
333 FIXME("(%p): stub\n", unknown
);
336 /***********************************************************************
337 * DllGetActivationFactory (combase.@)
339 HRESULT WINAPI
DllGetActivationFactory(HSTRING classid
, IActivationFactory
**factory
)
341 FIXME("(%s, %p): stub\n", debugstr_hstring(classid
), factory
);
343 return REGDB_E_CLASSNOTREG
;