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 "wine/debug.h"
29 WINE_DEFAULT_DEBUG_CHANNEL(combase
);
31 struct activatable_class_data
37 DWORD threading_model
;
40 static HRESULT
get_library_for_classid(const WCHAR
*classid
, WCHAR
**out
)
42 ACTCTX_SECTION_KEYED_DATA data
;
43 HKEY hkey_root
, hkey_class
;
50 /* search activation context first */
51 data
.cbSize
= sizeof(data
);
52 if (FindActCtxSectionStringW(FIND_ACTCTX_SECTION_KEY_RETURN_HACTCTX
, NULL
,
53 ACTIVATION_CONTEXT_SECTION_WINRT_ACTIVATABLE_CLASSES
, classid
, &data
))
55 struct activatable_class_data
*activatable_class
= (struct activatable_class_data
*)data
.lpData
;
56 void *ptr
= (BYTE
*)data
.lpSectionBase
+ activatable_class
->module_offset
;
61 /* load class registry key */
62 if (RegOpenKeyExW(HKEY_LOCAL_MACHINE
, L
"Software\\Microsoft\\WindowsRuntime\\ActivatableClassId",
63 0, KEY_READ
, &hkey_root
))
64 return REGDB_E_READREGDB
;
65 if (RegOpenKeyExW(hkey_root
, classid
, 0, KEY_READ
, &hkey_class
))
67 WARN("Class %s not found in registry\n", debugstr_w(classid
));
68 RegCloseKey(hkey_root
);
69 return REGDB_E_CLASSNOTREG
;
71 RegCloseKey(hkey_root
);
73 /* load (and expand) DllPath registry value */
74 if (RegQueryValueExW(hkey_class
, L
"DllPath", NULL
, &type
, NULL
, &size
))
76 hr
= REGDB_E_READREGDB
;
79 if (type
!= REG_SZ
&& type
!= REG_EXPAND_SZ
)
81 hr
= REGDB_E_READREGDB
;
84 if (!(buf
= malloc(size
)))
89 if (RegQueryValueExW(hkey_class
, L
"DllPath", NULL
, NULL
, (BYTE
*)buf
, &size
))
91 hr
= REGDB_E_READREGDB
;
94 if (type
== REG_EXPAND_SZ
)
97 DWORD len
= ExpandEnvironmentStringsW(buf
, NULL
, 0);
98 if (!(expanded
= malloc(len
* sizeof(WCHAR
))))
103 ExpandEnvironmentStringsW(buf
, expanded
, len
);
113 RegCloseKey(hkey_class
);
118 /***********************************************************************
119 * RoInitialize (combase.@)
121 HRESULT WINAPI
RoInitialize(RO_INIT_TYPE type
)
124 case RO_INIT_SINGLETHREADED
:
125 return CoInitializeEx(NULL
, COINIT_APARTMENTTHREADED
);
127 FIXME("type %d\n", type
);
128 case RO_INIT_MULTITHREADED
:
129 return CoInitializeEx(NULL
, COINIT_MULTITHREADED
);
133 /***********************************************************************
134 * RoUninitialize (combase.@)
136 void WINAPI
RoUninitialize(void)
141 /***********************************************************************
142 * RoGetActivationFactory (combase.@)
144 HRESULT WINAPI
RoGetActivationFactory(HSTRING classid
, REFIID iid
, void **class_factory
)
146 PFNGETACTIVATIONFACTORY pDllGetActivationFactory
;
147 IActivationFactory
*factory
;
152 FIXME("(%s, %s, %p): semi-stub\n", debugstr_hstring(classid
), debugstr_guid(iid
), class_factory
);
154 if (!iid
|| !class_factory
)
157 hr
= get_library_for_classid(WindowsGetStringRawBuffer(classid
, NULL
), &library
);
160 ERR("Failed to find library for %s\n", debugstr_hstring(classid
));
164 if (!(module
= LoadLibraryW(library
)))
166 ERR("Failed to load module %s\n", debugstr_w(library
));
167 hr
= HRESULT_FROM_WIN32(GetLastError());
171 if (!(pDllGetActivationFactory
= (void *)GetProcAddress(module
, "DllGetActivationFactory")))
173 ERR("Module %s does not implement DllGetActivationFactory\n", debugstr_w(library
));
178 TRACE("Found library %s for class %s\n", debugstr_w(library
), debugstr_hstring(classid
));
180 hr
= pDllGetActivationFactory(classid
, &factory
);
183 hr
= IActivationFactory_QueryInterface(factory
, iid
, class_factory
);
186 TRACE("Created interface %p\n", *class_factory
);
189 IActivationFactory_Release(factory
);
194 if (module
) FreeLibrary(module
);
198 /***********************************************************************
199 * RoGetParameterizedTypeInstanceIID (combase.@)
201 HRESULT WINAPI
RoGetParameterizedTypeInstanceIID(UINT32 name_element_count
, const WCHAR
**name_elements
,
202 const IRoMetaDataLocator
*meta_data_locator
, GUID
*iid
,
203 ROPARAMIIDHANDLE
*hiid
)
205 FIXME("stub: %d %p %p %p %p\n", name_element_count
, name_elements
, meta_data_locator
, iid
, hiid
);
206 if (iid
) *iid
= GUID_NULL
;
207 if (hiid
) *hiid
= INVALID_HANDLE_VALUE
;
211 /***********************************************************************
212 * RoActivateInstance (combase.@)
214 HRESULT WINAPI
RoActivateInstance(HSTRING classid
, IInspectable
**instance
)
216 IActivationFactory
*factory
;
219 FIXME("(%p, %p): semi-stub\n", classid
, instance
);
221 hr
= RoGetActivationFactory(classid
, &IID_IActivationFactory
, (void **)&factory
);
224 hr
= IActivationFactory_ActivateInstance(factory
, instance
);
225 IActivationFactory_Release(factory
);
231 /***********************************************************************
232 * RoGetApartmentIdentifier (combase.@)
234 HRESULT WINAPI
RoGetApartmentIdentifier(UINT64
*identifier
)
236 FIXME("(%p): stub\n", identifier
);
241 *identifier
= 0xdeadbeef;
245 /***********************************************************************
246 * RoRegisterForApartmentShutdown (combase.@)
248 HRESULT WINAPI
RoRegisterForApartmentShutdown(IApartmentShutdown
*callback
,
249 UINT64
*identifier
, APARTMENT_SHUTDOWN_REGISTRATION_COOKIE
*cookie
)
253 FIXME("(%p, %p, %p): stub\n", callback
, identifier
, cookie
);
255 hr
= RoGetApartmentIdentifier(identifier
);
260 *cookie
= (void *)0xcafecafe;
264 /***********************************************************************
265 * RoGetServerActivatableClasses (combase.@)
267 HRESULT WINAPI
RoGetServerActivatableClasses(HSTRING name
, HSTRING
**classes
, DWORD
*count
)
269 FIXME("(%p, %p, %p): stub\n", name
, classes
, count
);
276 /***********************************************************************
277 * RoRegisterActivationFactories (combase.@)
279 HRESULT WINAPI
RoRegisterActivationFactories(HSTRING
*classes
, PFNGETACTIVATIONFACTORY
*callbacks
,
280 UINT32 count
, RO_REGISTRATION_COOKIE
*cookie
)
282 FIXME("(%p, %p, %d, %p): stub\n", classes
, callbacks
, count
, cookie
);
287 /***********************************************************************
288 * GetRestrictedErrorInfo (combase.@)
290 HRESULT WINAPI
GetRestrictedErrorInfo(IRestrictedErrorInfo
**info
)
292 FIXME( "(%p)\n", info
);
296 /***********************************************************************
297 * RoOriginateLanguageException (combase.@)
299 BOOL WINAPI
RoOriginateLanguageException(HRESULT error
, HSTRING message
, IUnknown
*language_exception
)
301 FIXME("%#lx, %s, %p: stub\n", error
, debugstr_hstring(message
), language_exception
);
305 /***********************************************************************
306 * RoOriginateError (combase.@)
308 BOOL WINAPI
RoOriginateError(HRESULT error
, HSTRING message
)
310 FIXME("%#lx, %s: stub\n", error
, debugstr_hstring(message
));
314 /***********************************************************************
315 * RoSetErrorReportingFlags (combase.@)
317 HRESULT WINAPI
RoSetErrorReportingFlags(UINT32 flags
)
319 FIXME("(%08x): stub\n", flags
);
323 /***********************************************************************
324 * CleanupTlsOleState (combase.@)
326 void WINAPI
CleanupTlsOleState(void *unknown
)
328 FIXME("(%p): stub\n", unknown
);
331 /***********************************************************************
332 * DllGetActivationFactory (combase.@)
334 HRESULT WINAPI
DllGetActivationFactory(HSTRING classid
, IActivationFactory
**factory
)
336 FIXME("(%s, %p): stub\n", debugstr_hstring(classid
), factory
);
338 return REGDB_E_CLASSNOTREG
;