Skip to content

Commit 8f5edf6

Browse files
committed
Add a define (WINRT_NEVER_REG_FREE) that will break the build if linked against something using WINRT_REG_FREE
1 parent 04b00f4 commit 8f5edf6

File tree

3 files changed

+10
-4
lines changed

3 files changed

+10
-4
lines changed

strings/base_activation.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,8 +108,17 @@ namespace winrt::impl
108108
return 0U;
109109
}();
110110

111+
// This pragma is used to detect if the translation unit containing regfree usage is being linked with another translation
112+
// unit that declared WINRT_NEVER_REG_FREE.
113+
#pragma detect_mismatch("WINRT_REG_FREE", "enabled")
111114
#endif // WINRT_REG_FREE
112115

116+
#ifdef WINRT_NEVER_REG_FREE
117+
// This pragma is used to ensure that a binary will never have winrt regfree logic enabled. Defining WINRT_NEVER_REG_FREE will
118+
// cause this pragma to break linkage if any translation units in the same binary defined WINRT_REG_FREE.
119+
#pragma detect_mismatch("WINRT_REG_FREE", "never")
120+
#endif // WINRT_NEVER_REG_FREE
121+
113122
template <typename Interface>
114123
hresult get_runtime_activation_factory(param::hstring const& name, void** result) noexcept
115124
{

test/test_cpp20/activation_without_regfree.cpp

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,6 @@
11
#include "pch.h"
22
#include "winrt/test_component.h"
33

4-
#ifdef WINRT_REG_FREE
5-
#error "This test needs WINRT_REG_FREE to be undefined"
6-
#endif
7-
84
using namespace winrt;
95
using namespace Windows::Foundation;
106
using namespace test_component;

test/test_cpp20/pch.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
#pragma warning(4: 4458) // ensure we compile clean with this warning enabled
44

55
#define WINRT_LEAN_AND_MEAN
6+
#define WINRT_NEVER_REG_FREE
67
#include <unknwn.h>
78
#include "winrt/Windows.Data.Json.h"
89
#include "winrt/Windows.Foundation.h"

0 commit comments

Comments
 (0)