cppwinrt/— The cppwinrt.exe code generator (C++ source)main.cpp— CLI parsing, namespace iteration, SCC detection, .ixx orchestrationfile_writers.h— All file generation functions (headers, .ixx modules, component stubs)code_writers.h— Code-level writing utilities (guards, namespace wrappers, type writers)type_writers.h— Type formatting (ABI signatures, names, GUIDs)component_writers.h— Component authoring code generationhelpers.h— Metadata reading helperssettings.h— Global settings populated from CLI argstext_writer.h— Core text writer infrastructure
strings/— String literal.hfiles embedded by the prebuild step. Changes require: delete prebuild.exe → rebuild solutionnuget/— MSBuild targets, props, and NuGet packagingMicrosoft.Windows.CppWinRT.targets— Main MSBuild integration (projections, module support)
test/— Test projectstest/test_cpp20_module/— Standalone module test (in main solution)test/nuget/— NuGet integration tests (multi-project module chain)
docs/— Documentationnatvis/— Visual Studio debug visualizer (includes strings/*.h in its pch.h — add new files there too)
- Use VS Developer Shell for correct toolset environment
cmake --build build --config Release --target cppwinrtfor cppwinrt.exe (or MSBuild:msbuild cppwinrt\cppwinrt.vcxproj /p:Configuration=Release /p:Platform=x64)- NuGet tests:
msbuild test\nuget\NuGetTest.sln /p:Configuration=Release /p:Platform=x64 - Module test projects require v145 toolset (VS 2026). Directory.Build.Props sets v143 by default — override with
<PlatformToolset>v145</PlatformToolset>in Configuration PropertyGroup
The strings/*.h files are embedded as string literals by the prebuild step. If you modify any strings/*.h file, you must delete prebuild.exe and rebuild the entire solution for changes to take effect.
WINRT_IMPL_BUILD_MODULE— Defined in .ixx global fragment. MakesWINRT_EXPORTexpand toexport extern "C++"and suppresses#includeof dependenciesWINRT_IMPORT_MODULE— Defined by consumers who import modules. Makes namespace headers and base.h no-op (types come from module import)WINRT_EXPORT— Empty in header mode,export extern "C++"in module mode. Defined inwinrt/base_macros.hWINRT_IMPL_STD_EXPORT— Empty in header mode,extern "C++"(without export) in module mode. Used fornamespace stdspecializations
Each namespace produces four header files:
impl/<ns>.0.h— Forward declarations, ABIs, GUIDs, categoriesimpl/<ns>.1.h— Interface definitionsimpl/<ns>.2.h— Delegates, structs, class implementations<ns>.h— Public API surface (consume definitions, class wrappers, operators)
When generating headers with -modules, writer.depends is inspected after each header to build a namespace dependency graph. This graph drives SCC detection and module import lists.
- Module IFCs are NOT compatible across toolset versions — always clean rebuild when switching
- PCH and modules can coexist but PCH should NOT include winrt headers when using modules
/ifcSearchDirworks for the module dependency scanner to find IFCs, but cross-component modules may need explicit/reference "name=path.ifc"flagsimport std;requiresBuildStlModules=truestrings/base_macros.his the single source of truth for shared macros (generated aswinrt/base_macros.h). New macros go inbase_macros.honly- When adding, removing, or heavily refactoring
strings/*.hfiles, always rebuild the natvis project (natvis/cppwinrtvisualizer.sln) to verify — it includes strings/*.h directly in its pch.h