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 static HRESULT
get_library_for_classid(const WCHAR
*classid
, WCHAR
**out
)
42 HKEY hkey_root
, hkey_class
;
49 /* load class registry key */
50 if (RegOpenKeyExW(HKEY_LOCAL_MACHINE
, L
"Software\\Microsoft\\WindowsRuntime\\ActivatableClassId",
51 0, KEY_READ
, &hkey_root
))
52 return REGDB_E_READREGDB
;
53 if (RegOpenKeyExW(hkey_root
, classid
, 0, KEY_READ
, &hkey_class
))
55 WARN("Class %s not found in registry\n", debugstr_w(classid
));
56 RegCloseKey(hkey_root
);
57 return REGDB_E_CLASSNOTREG
;
59 RegCloseKey(hkey_root
);
61 /* load (and expand) DllPath registry value */
62 if (RegQueryValueExW(hkey_class
, L
"DllPath", NULL
, &type
, NULL
, &size
))
64 hr
= REGDB_E_READREGDB
;
67 if (type
!= REG_SZ
&& type
!= REG_EXPAND_SZ
)
69 hr
= REGDB_E_READREGDB
;
72 if (!(buf
= HeapAlloc(GetProcessHeap(), 0, size
)))
77 if (RegQueryValueExW(hkey_class
, L
"DllPath", NULL
, NULL
, (BYTE
*)buf
, &size
))
79 hr
= REGDB_E_READREGDB
;
82 if (type
== REG_EXPAND_SZ
)
85 DWORD len
= ExpandEnvironmentStringsW(buf
, NULL
, 0);
86 if (!(expanded
= HeapAlloc(GetProcessHeap(), 0, len
* sizeof(WCHAR
))))
91 ExpandEnvironmentStringsW(buf
, expanded
, len
);
92 HeapFree(GetProcessHeap(), 0, buf
);
100 HeapFree(GetProcessHeap(), 0, buf
);
101 RegCloseKey(hkey_class
);
106 /***********************************************************************
107 * RoInitialize (combase.@)
109 HRESULT WINAPI
RoInitialize(RO_INIT_TYPE type
)
112 case RO_INIT_SINGLETHREADED
:
113 return CoInitializeEx(NULL
, COINIT_APARTMENTTHREADED
);
115 FIXME("type %d\n", type
);
116 case RO_INIT_MULTITHREADED
:
117 return CoInitializeEx(NULL
, COINIT_MULTITHREADED
);
121 /***********************************************************************
122 * RoUninitialize (combase.@)
124 void WINAPI
RoUninitialize(void)
129 /***********************************************************************
130 * RoGetActivationFactory (combase.@)
132 HRESULT WINAPI
RoGetActivationFactory(HSTRING classid
, REFIID iid
, void **class_factory
)
134 PFNGETACTIVATIONFACTORY pDllGetActivationFactory
;
135 IActivationFactory
*factory
;
140 FIXME("(%s, %s, %p): semi-stub\n", debugstr_hstring(classid
), debugstr_guid(iid
), class_factory
);
142 if (!iid
|| !class_factory
)
145 hr
= get_library_for_classid(WindowsGetStringRawBuffer(classid
, NULL
), &library
);
148 ERR("Failed to find library for %s\n", debugstr_hstring(classid
));
152 if (!(module
= LoadLibraryW(library
)))
154 ERR("Failed to load module %s\n", debugstr_w(library
));
155 hr
= HRESULT_FROM_WIN32(GetLastError());
159 if (!(pDllGetActivationFactory
= (void *)GetProcAddress(module
, "DllGetActivationFactory")))
161 ERR("Module %s does not implement DllGetActivationFactory\n", debugstr_w(library
));
166 TRACE("Found library %s for class %s\n", debugstr_w(library
), debugstr_hstring(classid
));
168 hr
= pDllGetActivationFactory(classid
, &factory
);
171 hr
= IActivationFactory_QueryInterface(factory
, iid
, class_factory
);
174 TRACE("Created interface %p\n", *class_factory
);
177 IActivationFactory_Release(factory
);
181 HeapFree(GetProcessHeap(), 0, library
);
182 if (module
) FreeLibrary(module
);
186 /***********************************************************************
187 * RoGetParameterizedTypeInstanceIID (combase.@)
189 HRESULT WINAPI
RoGetParameterizedTypeInstanceIID(UINT32 name_element_count
, const WCHAR
**name_elements
,
190 const IRoMetaDataLocator
*meta_data_locator
, GUID
*iid
,
191 ROPARAMIIDHANDLE
*hiid
)
193 FIXME("stub: %d %p %p %p %p\n", name_element_count
, name_elements
, meta_data_locator
, iid
, hiid
);
194 if (iid
) *iid
= GUID_NULL
;
195 if (hiid
) *hiid
= INVALID_HANDLE_VALUE
;
199 /***********************************************************************
200 * RoActivateInstance (combase.@)
202 HRESULT WINAPI
RoActivateInstance(HSTRING classid
, IInspectable
**instance
)
204 IActivationFactory
*factory
;
207 FIXME("(%p, %p): semi-stub\n", classid
, instance
);
209 hr
= RoGetActivationFactory(classid
, &IID_IActivationFactory
, (void **)&factory
);
212 hr
= IActivationFactory_ActivateInstance(factory
, instance
);
213 IActivationFactory_Release(factory
);
219 /***********************************************************************
220 * RoGetApartmentIdentifier (combase.@)
222 HRESULT WINAPI
RoGetApartmentIdentifier(UINT64
*identifier
)
224 FIXME("(%p): stub\n", identifier
);
229 *identifier
= 0xdeadbeef;
233 /***********************************************************************
234 * RoRegisterForApartmentShutdown (combase.@)
236 HRESULT WINAPI
RoRegisterForApartmentShutdown(IApartmentShutdown
*callback
,
237 UINT64
*identifier
, APARTMENT_SHUTDOWN_REGISTRATION_COOKIE
*cookie
)
241 FIXME("(%p, %p, %p): stub\n", callback
, identifier
, cookie
);
243 hr
= RoGetApartmentIdentifier(identifier
);
248 *cookie
= (void *)0xcafecafe;
252 /***********************************************************************
253 * RoGetServerActivatableClasses (combase.@)
255 HRESULT WINAPI
RoGetServerActivatableClasses(HSTRING name
, HSTRING
**classes
, DWORD
*count
)
257 FIXME("(%p, %p, %p): stub\n", name
, classes
, count
);
264 /***********************************************************************
265 * RoRegisterActivationFactories (combase.@)
267 HRESULT WINAPI
RoRegisterActivationFactories(HSTRING
*classes
, PFNGETACTIVATIONFACTORY
*callbacks
,
268 UINT32 count
, RO_REGISTRATION_COOKIE
*cookie
)
270 FIXME("(%p, %p, %d, %p): stub\n", classes
, callbacks
, count
, cookie
);
275 /***********************************************************************
276 * GetRestrictedErrorInfo (combase.@)
278 HRESULT WINAPI
GetRestrictedErrorInfo(IRestrictedErrorInfo
**info
)
280 FIXME( "(%p)\n", info
);
284 /***********************************************************************
285 * RoOriginateLanguageException (combase.@)
287 BOOL WINAPI
RoOriginateLanguageException(HRESULT error
, HSTRING message
, IUnknown
*language_exception
)
289 FIXME("(%x %s %p) stub\n", error
, debugstr_hstring(message
), language_exception
);
293 /***********************************************************************
294 * CleanupTlsOleState (combase.@)
296 void WINAPI
CleanupTlsOleState(void *unknown
)
298 FIXME("(%p): stub\n", unknown
);
301 /***********************************************************************
302 * DllGetActivationFactory (combase.@)
304 HRESULT WINAPI
DllGetActivationFactory(HSTRING classid
, IActivationFactory
**factory
)
306 FIXME("(%s, %p): stub\n", debugstr_hstring(classid
), factory
);
308 return REGDB_E_CLASSNOTREG
;