diff --git a/MyDllServerWinRt/Main.cpp b/MyDllServerWinRt/Main.cpp index a380bbc..bcf33cb 100644 --- a/MyDllServerWinRt/Main.cpp +++ b/MyDllServerWinRt/Main.cpp @@ -1,6 +1,7 @@ #include #include #include +#include #include "../support/WinRtUtils.hpp" #include "../MyExeServerWinRt/MyServerImpl.hpp" @@ -32,8 +33,8 @@ STDAPI DllGetClassObject(::GUID const& clsid, ::GUID const& iid, void** result) *result = nullptr; if (clsid == __uuidof(MyServer)) { - // TODO: Replace with wil::details::CppWinRTClassFactory after https://github.com/microsoft/wil/issues/534 is resolved - return winrt::make>().as(iid, result); + // TODO: Avoid relying on an "internal" WIL class here (see https://github.com/microsoft/wil/issues/534) + return winrt::make>().as(iid, result); } return CLASS_E_CLASSNOTAVAILABLE; diff --git a/MyDllServerWinRt/MyDllServerWinRt.vcxproj b/MyDllServerWinRt/MyDllServerWinRt.vcxproj index 904dc1b..f411215 100644 --- a/MyDllServerWinRt/MyDllServerWinRt.vcxproj +++ b/MyDllServerWinRt/MyDllServerWinRt.vcxproj @@ -101,6 +101,7 @@ + @@ -114,5 +115,6 @@ + \ No newline at end of file diff --git a/MyDllServerWinRt/packages.config b/MyDllServerWinRt/packages.config index f32f48b..3a8e069 100644 --- a/MyDllServerWinRt/packages.config +++ b/MyDllServerWinRt/packages.config @@ -1,4 +1,5 @@  + \ No newline at end of file diff --git a/MyExeServerWinRt/Main.cpp b/MyExeServerWinRt/Main.cpp index 81eec7c..4235931 100644 --- a/MyExeServerWinRt/Main.cpp +++ b/MyExeServerWinRt/Main.cpp @@ -4,6 +4,7 @@ #define WINRT_CUSTOM_MODULE_LOCK #include #include +#include #include "../support/WinRtUtils.hpp" #include "MyServerImpl.hpp" @@ -40,9 +41,8 @@ int wmain(int argc, wchar_t* argv[]) { }); // register class factory in current process - // TODO: Replace with wil::register_com_server after https://github.com/microsoft/wil/pull/533 is fixed. - DWORD registration = 0; - winrt::check_hresult(::CoRegisterClassObject(__uuidof(MyServer), winrt::make>().get(), CLSCTX_LOCAL_SERVER, REGCLS_MULTIPLEUSE, ®istration)); + // TODO: Fix buggy wil::register_com_server implementation (see https://github.com/microsoft/wil/pull/533) + auto revoker = wil::register_com_server(); // registers with CLSCTX_LOCAL_SERVER, REGCLS_MULTIPLEUSE wprintf(L"Waiting for COM class creation requests...\n"); diff --git a/MyExeServerWinRt/MyServerImpl.hpp b/MyExeServerWinRt/MyServerImpl.hpp index 7d90426..97d9709 100644 --- a/MyExeServerWinRt/MyServerImpl.hpp +++ b/MyExeServerWinRt/MyServerImpl.hpp @@ -32,7 +32,8 @@ class NumberCruncher : public winrt::implements { +class __declspec(uuid("AF080472-F173-4D9D-8BE7-435776617347")) // __uuidof(MyServer) +MyServerImpl : public winrt::implements { public: MyServerImpl() { #ifndef NDEBUG diff --git a/support/WinRtUtils.hpp b/support/WinRtUtils.hpp index 8f1cbf1..49d589b 100644 --- a/support/WinRtUtils.hpp +++ b/support/WinRtUtils.hpp @@ -10,38 +10,6 @@ #include "../support/CurrentModule.hpp" -/** Minimal COM class factory implementation. - TODO: Replace with wil::detail::CppWinRTClassFactory after https://github.com/microsoft/wil/pull/533 and https://github.com/microsoft/wil/issues/534 are resolved. */ -template -class ClassFactory : public winrt::implements, IClassFactory, winrt::no_module_lock> { -public: - ClassFactory() { -#ifndef NDEBUG - wprintf(L"ClassFactory ctor\n"); -#endif - } - - ~ClassFactory() { -#ifndef NDEBUG - wprintf(L"ClassFactory dtor\n"); -#endif - } - - HRESULT CreateInstance(IUnknown* outer, const IID& iid, void** result) noexcept override { - *result = nullptr; - if (outer) - return CLASS_E_NOAGGREGATION; // aggregation not supported yet - - // create object - return winrt::make().as(iid, result); - } - - HRESULT LockServer(BOOL) noexcept override { - return S_OK; - } -}; - - /** COM type library (un)registration function. TODO: Replace this function with WIL alternative if https://github.com/microsoft/wil/issues/531 is resolved. */ ::GUID RegisterTypeLibrary(bool do_register, std::wstring tlb_path) {