Skip to content

Commit ce660af

Browse files
committed
Stop exporting winrt::impl::get_marshaler to workaround MSVC modules bug
1 parent c4cf531 commit ce660af

3 files changed

Lines changed: 28 additions & 2 deletions

File tree

strings/base_marshaler.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11

2-
WINRT_EXPORT namespace winrt::impl
2+
namespace winrt::impl
33
{
44
inline std::int32_t make_marshaler(unknown_abi* outer, void** result) noexcept
55
{

test/test_cpp20_module/marshal.cpp

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
#include "pch.h"
2+
#include <objidl.h>
3+
4+
import std;
5+
import winrt.Windows.Foundation.Collections;
6+
7+
using namespace winrt;
8+
9+
struct S : implements<S, Windows::Foundation::IStringable>
10+
{
11+
hstring ToString()
12+
{
13+
return L"S";
14+
}
15+
};
16+
17+
// When winrt::impl::get_marshaler was being exported, an MSVC bug caused the marshaler
18+
// object to have a null vtable, which caused a crash when calling any method on the marshaler.
19+
// This test ensures that the marshaler vtable is properly initialized.
20+
TEST_CASE("IMarshal")
21+
{
22+
auto s = make<S>();
23+
auto marshal = s.as<IMarshal>();
24+
}

test/test_cpp20_module/test_cpp20_module.vcxproj

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@
2525
<Configuration>Release</Configuration>
2626
<Platform>x64</Platform>
2727
</ProjectConfiguration>
28-
</ItemGroup> <PropertyGroup Label="Globals">
28+
</ItemGroup>
29+
<PropertyGroup Label="Globals">
2930
<VCProjectVersion>16.0</VCProjectVersion>
3031
<ProjectGuid>{B8E3A5CE-4E91-4F27-9B02-E0CAF7E10D72}</ProjectGuid>
3132
<RootNamespace>test_cpp20_module</RootNamespace>
@@ -91,6 +92,7 @@
9192
<ClInclude Include="pch.h" />
9293
</ItemGroup>
9394
<ItemGroup>
95+
<ClCompile Include="marshal.cpp" />
9496
<ClCompile Include="pch.cpp">
9597
<PrecompiledHeader>Create</PrecompiledHeader>
9698
</ClCompile>

0 commit comments

Comments
 (0)