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 static const char *debugstr_hstring(HSTRING hstr
)
35 if (hstr
&& !((ULONG_PTR
)hstr
>> 16)) return "(invalid)";
36 str
= WindowsGetStringRawBuffer(hstr
, &len
);
37 return wine_dbgstr_wn(str
, len
);
40 struct activatable_class_data
46 DWORD threading_model
;
49 static HRESULT
get_library_for_classid(const WCHAR
*classid
, WCHAR
**out
)
51 ACTCTX_SECTION_KEYED_DATA data
;
52 HKEY hkey_root
, hkey_class
;
59 /* search activation context first */
60 data
.cbSize
= sizeof(data
);
61 if (FindActCtxSectionStringW(FIND_ACTCTX_SECTION_KEY_RETURN_HACTCTX
, NULL
,
62 ACTIVATION_CONTEXT_SECTION_WINRT_ACTIVATABLE_CLASSES
, classid
, &data
))
64 struct activatable_class_data
*activatable_class
= (struct activatable_class_data
*)data
.lpData
;
65 void *ptr
= (BYTE
*)data
.lpSectionBase
+ activatable_class
->module_offset
;
70 /* load class registry key */
71 if (RegOpenKeyExW(HKEY_LOCAL_MACHINE
, L
"Software\\Microsoft\\WindowsRuntime\\ActivatableClassId",
72 0, KEY_READ
, &hkey_root
))
73 return REGDB_E_READREGDB
;
74 if (RegOpenKeyExW(hkey_root
, classid
, 0, KEY_READ
, &hkey_class
))
76 WARN("Class %s not found in registry\n", debugstr_w(classid
));
77 RegCloseKey(hkey_root
);
78 return REGDB_E_CLASSNOTREG
;
80 RegCloseKey(hkey_root
);
82 /* load (and expand) DllPath registry value */
83 if (RegQueryValueExW(hkey_class
, L
"DllPath", NULL
, &type
, NULL
, &size
))
85 hr
= REGDB_E_READREGDB
;
88 if (type
!= REG_SZ
&& type
!= REG_EXPAND_SZ
)
90 hr
= REGDB_E_READREGDB
;
93 if (!(buf
= malloc(size
)))
98 if (RegQueryValueExW(hkey_class
, L
"DllPath", NULL
, NULL
, (BYTE
*)buf
, &size
))
100 hr
= REGDB_E_READREGDB
;
103 if (type
== REG_EXPAND_SZ
)
106 DWORD len
= ExpandEnvironmentStringsW(buf
, NULL
, 0);
107 if (!(expanded
= malloc(len
* sizeof(WCHAR
))))
112 ExpandEnvironmentStringsW(buf
, expanded
, len
);
122 RegCloseKey(hkey_class
);
127 /***********************************************************************
128 * RoInitialize (combase.@)
130 HRESULT WINAPI
RoInitialize(RO_INIT_TYPE type
)
133 case RO_INIT_SINGLETHREADED
:
134 return CoInitializeEx(NULL
, COINIT_APARTMENTTHREADED
);
136 FIXME("type %d\n", type
);
137 case RO_INIT_MULTITHREADED
:
138 return CoInitializeEx(NULL
, COINIT_MULTITHREADED
);
142 /***********************************************************************
143 * RoUninitialize (combase.@)
145 void WINAPI
RoUninitialize(void)
150 /***********************************************************************
151 * RoGetActivationFactory (combase.@)
153 HRESULT WINAPI
RoGetActivationFactory(HSTRING classid
, REFIID iid
, void **class_factory
)
155 PFNGETACTIVATIONFACTORY pDllGetActivationFactory
;
156 IActivationFactory
*factory
;
161 FIXME("(%s, %s, %p): semi-stub\n", debugstr_hstring(classid
), debugstr_guid(iid
), class_factory
);
163 if (!iid
|| !class_factory
)
166 hr
= get_library_for_classid(WindowsGetStringRawBuffer(classid
, NULL
), &library
);
169 ERR("Failed to find library for %s\n", debugstr_hstring(classid
));
173 if (!(module
= LoadLibraryW(library
)))
175 ERR("Failed to load module %s\n", debugstr_w(library
));
176 hr
= HRESULT_FROM_WIN32(GetLastError());
180 if (!(pDllGetActivationFactory
= (void *)GetProcAddress(module
, "DllGetActivationFactory")))
182 ERR("Module %s does not implement DllGetActivationFactory\n", debugstr_w(library
));
187 TRACE("Found library %s for class %s\n", debugstr_w(library
), debugstr_hstring(classid
));
189 hr
= pDllGetActivationFactory(classid
, &factory
);
192 hr
= IActivationFactory_QueryInterface(factory
, iid
, class_factory
);
195 TRACE("Created interface %p\n", *class_factory
);
198 IActivationFactory_Release(factory
);
203 if (module
) FreeLibrary(module
);
207 /***********************************************************************
208 * RoGetParameterizedTypeInstanceIID (combase.@)
210 HRESULT WINAPI
RoGetParameterizedTypeInstanceIID(UINT32 name_element_count
, const WCHAR
**name_elements
,
211 const IRoMetaDataLocator
*meta_data_locator
, GUID
*iid
,
212 ROPARAMIIDHANDLE
*hiid
)
214 FIXME("stub: %d %p %p %p %p\n", name_element_count
, name_elements
, meta_data_locator
, iid
, hiid
);
215 if (iid
) *iid
= GUID_NULL
;
216 if (hiid
) *hiid
= INVALID_HANDLE_VALUE
;
220 /***********************************************************************
221 * RoActivateInstance (combase.@)
223 HRESULT WINAPI
RoActivateInstance(HSTRING classid
, IInspectable
**instance
)
225 IActivationFactory
*factory
;
228 FIXME("(%p, %p): semi-stub\n", classid
, instance
);
230 hr
= RoGetActivationFactory(classid
, &IID_IActivationFactory
, (void **)&factory
);
233 hr
= IActivationFactory_ActivateInstance(factory
, instance
);
234 IActivationFactory_Release(factory
);
240 /***********************************************************************
241 * RoGetApartmentIdentifier (combase.@)
243 HRESULT WINAPI
RoGetApartmentIdentifier(UINT64
*identifier
)
245 FIXME("(%p): stub\n", identifier
);
250 *identifier
= 0xdeadbeef;
254 /***********************************************************************
255 * RoRegisterForApartmentShutdown (combase.@)
257 HRESULT WINAPI
RoRegisterForApartmentShutdown(IApartmentShutdown
*callback
,
258 UINT64
*identifier
, APARTMENT_SHUTDOWN_REGISTRATION_COOKIE
*cookie
)
262 FIXME("(%p, %p, %p): stub\n", callback
, identifier
, cookie
);
264 hr
= RoGetApartmentIdentifier(identifier
);
269 *cookie
= (void *)0xcafecafe;
273 /***********************************************************************
274 * RoGetServerActivatableClasses (combase.@)
276 HRESULT WINAPI
RoGetServerActivatableClasses(HSTRING name
, HSTRING
**classes
, DWORD
*count
)
278 FIXME("(%p, %p, %p): stub\n", name
, classes
, count
);
285 /***********************************************************************
286 * RoRegisterActivationFactories (combase.@)
288 HRESULT WINAPI
RoRegisterActivationFactories(HSTRING
*classes
, PFNGETACTIVATIONFACTORY
*callbacks
,
289 UINT32 count
, RO_REGISTRATION_COOKIE
*cookie
)
291 FIXME("(%p, %p, %d, %p): stub\n", classes
, callbacks
, count
, cookie
);
296 /***********************************************************************
297 * GetRestrictedErrorInfo (combase.@)
299 HRESULT WINAPI
GetRestrictedErrorInfo(IRestrictedErrorInfo
**info
)
301 FIXME( "(%p)\n", info
);
305 /***********************************************************************
306 * RoOriginateLanguageException (combase.@)
308 BOOL WINAPI
RoOriginateLanguageException(HRESULT error
, HSTRING message
, IUnknown
*language_exception
)
310 FIXME("%#lx, %s, %p: stub\n", error
, debugstr_hstring(message
), language_exception
);
314 /***********************************************************************
315 * RoOriginateError (combase.@)
317 BOOL WINAPI
RoOriginateError(HRESULT error
, HSTRING message
)
319 FIXME("%#lx, %s: stub\n", error
, debugstr_hstring(message
));
323 /***********************************************************************
324 * RoSetErrorReportingFlags (combase.@)
326 HRESULT WINAPI
RoSetErrorReportingFlags(UINT32 flags
)
328 FIXME("(%08x): stub\n", flags
);
332 /***********************************************************************
333 * CleanupTlsOleState (combase.@)
335 void WINAPI
CleanupTlsOleState(void *unknown
)
337 FIXME("(%p): stub\n", unknown
);
340 /***********************************************************************
341 * DllGetActivationFactory (combase.@)
343 HRESULT WINAPI
DllGetActivationFactory(HSTRING classid
, IActivationFactory
**factory
)
345 FIXME("(%s, %p): stub\n", debugstr_hstring(classid
), factory
);
347 return REGDB_E_CLASSNOTREG
;