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 static const WCHAR classkeyW
[] = {'S','o','f','t','w','a','r','e','\\',
43 'M','i','c','r','o','s','o','f','t','\\',
44 'W','i','n','d','o','w','s','R','u','n','t','i','m','e','\\',
45 'A','c','t','i','v','a','t','a','b','l','e','C','l','a','s','s','I','d',0};
46 static const WCHAR dllpathW
[] = {'D','l','l','P','a','t','h',0};
47 HKEY hkey_root
, hkey_class
;
54 /* load class registry key */
55 if (RegOpenKeyExW(HKEY_LOCAL_MACHINE
, classkeyW
, 0, KEY_READ
, &hkey_root
))
56 return REGDB_E_READREGDB
;
57 if (RegOpenKeyExW(hkey_root
, classid
, 0, KEY_READ
, &hkey_class
))
59 WARN("Class %s not found in registry\n", debugstr_w(classid
));
60 RegCloseKey(hkey_root
);
61 return REGDB_E_CLASSNOTREG
;
63 RegCloseKey(hkey_root
);
65 /* load (and expand) DllPath registry value */
66 if (RegQueryValueExW(hkey_class
, dllpathW
, NULL
, &type
, NULL
, &size
))
68 hr
= REGDB_E_READREGDB
;
71 if (type
!= REG_SZ
&& type
!= REG_EXPAND_SZ
)
73 hr
= REGDB_E_READREGDB
;
76 if (!(buf
= HeapAlloc(GetProcessHeap(), 0, size
)))
81 if (RegQueryValueExW(hkey_class
, dllpathW
, NULL
, NULL
, (BYTE
*)buf
, &size
))
83 hr
= REGDB_E_READREGDB
;
86 if (type
== REG_EXPAND_SZ
)
89 DWORD len
= ExpandEnvironmentStringsW(buf
, NULL
, 0);
90 if (!(expanded
= HeapAlloc(GetProcessHeap(), 0, len
* sizeof(WCHAR
))))
95 ExpandEnvironmentStringsW(buf
, expanded
, len
);
96 HeapFree(GetProcessHeap(), 0, buf
);
104 HeapFree(GetProcessHeap(), 0, buf
);
105 RegCloseKey(hkey_class
);
110 /***********************************************************************
111 * RoInitialize (combase.@)
113 HRESULT WINAPI
RoInitialize(RO_INIT_TYPE type
)
116 case RO_INIT_SINGLETHREADED
:
117 return CoInitializeEx(NULL
, COINIT_APARTMENTTHREADED
);
119 FIXME("type %d\n", type
);
120 case RO_INIT_MULTITHREADED
:
121 return CoInitializeEx(NULL
, COINIT_MULTITHREADED
);
125 /***********************************************************************
126 * RoUninitialize (combase.@)
128 void WINAPI
RoUninitialize(void)
133 /***********************************************************************
134 * RoGetActivationFactory (combase.@)
136 HRESULT WINAPI
RoGetActivationFactory(HSTRING classid
, REFIID iid
, void **class_factory
)
138 PFNGETACTIVATIONFACTORY pDllGetActivationFactory
;
139 IActivationFactory
*factory
;
144 FIXME("(%s, %s, %p): semi-stub\n", debugstr_hstring(classid
), debugstr_guid(iid
), class_factory
);
146 if (!iid
|| !class_factory
)
149 hr
= get_library_for_classid(WindowsGetStringRawBuffer(classid
, NULL
), &library
);
152 ERR("Failed to find library for %s\n", debugstr_hstring(classid
));
156 if (!(module
= LoadLibraryW(library
)))
158 ERR("Failed to load module %s\n", debugstr_w(library
));
159 hr
= HRESULT_FROM_WIN32(GetLastError());
163 if (!(pDllGetActivationFactory
= (void *)GetProcAddress(module
, "DllGetActivationFactory")))
165 ERR("Module %s does not implement DllGetActivationFactory\n", debugstr_w(library
));
170 TRACE("Found library %s for class %s\n", debugstr_w(library
), debugstr_hstring(classid
));
172 hr
= pDllGetActivationFactory(classid
, &factory
);
175 hr
= IActivationFactory_QueryInterface(factory
, iid
, class_factory
);
178 TRACE("Created interface %p\n", *class_factory
);
181 IActivationFactory_Release(factory
);
185 HeapFree(GetProcessHeap(), 0, library
);
186 if (module
) FreeLibrary(module
);
190 /***********************************************************************
191 * RoGetParameterizedTypeInstanceIID (combase.@)
193 HRESULT WINAPI
RoGetParameterizedTypeInstanceIID(UINT32 name_element_count
, const WCHAR
**name_elements
,
194 const IRoMetaDataLocator
*meta_data_locator
, GUID
*iid
,
195 ROPARAMIIDHANDLE
*hiid
)
197 FIXME("stub: %d %p %p %p %p\n", name_element_count
, name_elements
, meta_data_locator
, iid
, hiid
);
198 if (iid
) *iid
= GUID_NULL
;
199 if (hiid
) *hiid
= INVALID_HANDLE_VALUE
;
203 /***********************************************************************
204 * RoActivateInstance (combase.@)
206 HRESULT WINAPI
RoActivateInstance(HSTRING classid
, IInspectable
**instance
)
208 IActivationFactory
*factory
;
211 FIXME("(%p, %p): semi-stub\n", classid
, instance
);
213 hr
= RoGetActivationFactory(classid
, &IID_IActivationFactory
, (void **)&factory
);
216 hr
= IActivationFactory_ActivateInstance(factory
, instance
);
217 IActivationFactory_Release(factory
);
223 /***********************************************************************
224 * RoGetApartmentIdentifier (combase.@)
226 HRESULT WINAPI
RoGetApartmentIdentifier(UINT64
*identifier
)
228 FIXME("(%p): stub\n", identifier
);
233 *identifier
= 0xdeadbeef;
237 /***********************************************************************
238 * RoRegisterForApartmentShutdown (combase.@)
240 HRESULT WINAPI
RoRegisterForApartmentShutdown(IApartmentShutdown
*callback
,
241 UINT64
*identifier
, APARTMENT_SHUTDOWN_REGISTRATION_COOKIE
*cookie
)
245 FIXME("(%p, %p, %p): stub\n", callback
, identifier
, cookie
);
247 hr
= RoGetApartmentIdentifier(identifier
);
252 *cookie
= (void *)0xcafecafe;
256 /***********************************************************************
257 * RoGetServerActivatableClasses (combase.@)
259 HRESULT WINAPI
RoGetServerActivatableClasses(HSTRING name
, HSTRING
**classes
, DWORD
*count
)
261 FIXME("(%p, %p, %p): stub\n", name
, classes
, count
);
268 /***********************************************************************
269 * RoRegisterActivationFactories (combase.@)
271 HRESULT WINAPI
RoRegisterActivationFactories(HSTRING
*classes
, PFNGETACTIVATIONFACTORY
*callbacks
,
272 UINT32 count
, RO_REGISTRATION_COOKIE
*cookie
)
274 FIXME("(%p, %p, %d, %p): stub\n", classes
, callbacks
, count
, cookie
);
279 /***********************************************************************
280 * GetRestrictedErrorInfo (combase.@)
282 HRESULT WINAPI
GetRestrictedErrorInfo(IRestrictedErrorInfo
**info
)
284 FIXME( "(%p)\n", info
);
288 /***********************************************************************
289 * RoOriginateLanguageException (combase.@)
291 BOOL WINAPI
RoOriginateLanguageException(HRESULT error
, HSTRING message
, IUnknown
*language_exception
)
293 FIXME("(%x %s %p) stub\n", error
, debugstr_hstring(message
), language_exception
);
297 /***********************************************************************
298 * CleanupTlsOleState (combase.@)
300 void WINAPI
CleanupTlsOleState(void *unknown
)
302 FIXME("(%p): stub\n", unknown
);
305 /***********************************************************************
306 * DllGetActivationFactory (combase.@)
308 HRESULT WINAPI
DllGetActivationFactory(HSTRING classid
, IActivationFactory
**factory
)
310 FIXME("(%s, %p): stub\n", debugstr_hstring(classid
), factory
);
312 return REGDB_E_CLASSNOTREG
;