Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions MyDllServerWinRt/Main.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include <Windows.h>
#include <unknwn.h>
#include <winrt/Windows.Foundation.h>
#include <wil/cppwinrt_register_com_server.h>
#include "../support/WinRtUtils.hpp"
#include "../MyExeServerWinRt/MyServerImpl.hpp"

Expand Down Expand Up @@ -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<ClassFactory<MyServerImpl>>().as(iid, result);
// TODO: Avoid relying on an "internal" WIL class here (see https://github.com/microsoft/wil/issues/534)
return winrt::make<wil::details::CppWinRTClassFactory<MyServerImpl>>().as(iid, result);
}

return CLASS_E_CLASSNOTAVAILABLE;
Expand Down
2 changes: 2 additions & 0 deletions MyDllServerWinRt/MyDllServerWinRt.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
<Import Project="..\packages\Microsoft.Windows.CppWinRT.2.0.250303.1\build\native\Microsoft.Windows.CppWinRT.targets" Condition="Exists('..\packages\Microsoft.Windows.CppWinRT.2.0.250303.1\build\native\Microsoft.Windows.CppWinRT.targets')" />
<Import Project="..\packages\Microsoft.Windows.ImplementationLibrary.1.0.250325.1\build\native\Microsoft.Windows.ImplementationLibrary.targets" Condition="Exists('..\packages\Microsoft.Windows.ImplementationLibrary.1.0.250325.1\build\native\Microsoft.Windows.ImplementationLibrary.targets')" />
</ImportGroup>
<Target Name="ServerUsage" AfterTargets="Build" DependsOnTargets="AssignTargetPaths">
<Message Importance="High" Text="%0a**************************************%0a*** $(MSBuildProjectName) usage instructions ***%0a**************************************" />
Expand All @@ -114,5 +115,6 @@
</PropertyGroup>
<Error Condition="!Exists('..\packages\Microsoft.Windows.CppWinRT.2.0.250303.1\build\native\Microsoft.Windows.CppWinRT.props')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Microsoft.Windows.CppWinRT.2.0.250303.1\build\native\Microsoft.Windows.CppWinRT.props'))" />
<Error Condition="!Exists('..\packages\Microsoft.Windows.CppWinRT.2.0.250303.1\build\native\Microsoft.Windows.CppWinRT.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Microsoft.Windows.CppWinRT.2.0.250303.1\build\native\Microsoft.Windows.CppWinRT.targets'))" />
<Error Condition="!Exists('..\packages\Microsoft.Windows.ImplementationLibrary.1.0.250325.1\build\native\Microsoft.Windows.ImplementationLibrary.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Microsoft.Windows.ImplementationLibrary.1.0.250325.1\build\native\Microsoft.Windows.ImplementationLibrary.targets'))" />
</Target>
</Project>
1 change: 1 addition & 0 deletions MyDllServerWinRt/packages.config
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="Microsoft.Windows.CppWinRT" version="2.0.250303.1" targetFramework="native" />
<package id="Microsoft.Windows.ImplementationLibrary" version="1.0.250325.1" targetFramework="native" />
</packages>
6 changes: 3 additions & 3 deletions MyExeServerWinRt/Main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#define WINRT_CUSTOM_MODULE_LOCK
#include <wil/resource.h>
#include <wil/cppwinrt_notifiable_module_lock.h>
#include <wil/cppwinrt_register_com_server.h>

#include "../support/WinRtUtils.hpp"
#include "MyServerImpl.hpp"
Expand Down Expand Up @@ -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<ClassFactory<MyServerImpl>>().get(), CLSCTX_LOCAL_SERVER, REGCLS_MULTIPLEUSE, &registration));
// TODO: Fix buggy wil::register_com_server implementation (see https://github.com/microsoft/wil/pull/533)
auto revoker = wil::register_com_server<MyServerImpl>(); // registers with CLSCTX_LOCAL_SERVER, REGCLS_MULTIPLEUSE

wprintf(L"Waiting for COM class creation requests...\n");

Expand Down
3 changes: 2 additions & 1 deletion MyExeServerWinRt/MyServerImpl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ class NumberCruncher : public winrt::implements<NumberCruncher, INumberCruncher,


/** Creatable COM class that needs a CLSID. */
class MyServerImpl : public winrt::implements<MyServerImpl, IMyServer, winrt::no_weak_ref> {
class __declspec(uuid("AF080472-F173-4D9D-8BE7-435776617347")) // __uuidof(MyServer)
MyServerImpl : public winrt::implements<MyServerImpl, IMyServer, winrt::no_weak_ref> {
public:
MyServerImpl() {
#ifndef NDEBUG
Expand Down
32 changes: 0 additions & 32 deletions support/WinRtUtils.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 T>
class ClassFactory : public winrt::implements<ClassFactory<T>, 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<T>().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) {
Expand Down