-
Notifications
You must be signed in to change notification settings - Fork 275
Description
I've just started modernizing some existing ATL projects to WinRT. One challenge then faced has been how to implement DllGetClassObject in a DLL-based COM server. ATL already includes boilerplate code for this, but similar functionality seem to be missing from C++/WinRT and WIL.
There's documentation on how to implement DllGetClassObject with a custom class factory on Author COM components with C++/WinRT. This works fine, but require developers to add their own class factory implementation, which leads to boilerplate.
To reduce boilerplate, I've started using the WIL CppWinRTClassFactory class to simplify the DllGetClassObject implementation, and then end up with code like this:
STDAPI DllGetClassObject(::GUID const& clsid, ::GUID const& iid, void** result) {
*result = nullptr;
if (clsid == __uuidof(MyServer)) {
return winrt::make<wil::details::CppWinRTClassFactory<MyServer>>().as(iid, result);
}
return CLASS_E_CLASSNOTAVAILABLE;
}
This works fine, but introduces a dependency to a wil::details class, and I'm unsure if this is recommended.
REQUEST: There's already a wil::register_com_server function in this repo to ease implementation of EXE-based COM servers. It would therefore be great if something similar could exist for DLL-based COM servers. One solution could then be to endorse direct CppWinRTClassFactory usage, or provide a more complete DllGetClassObject implementation.