-
Notifications
You must be signed in to change notification settings - Fork 320
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Improved C++ item & templates #3619
Open
JaiganeshKumaran
wants to merge
10
commits into
microsoft:main-old
Choose a base branch
from
JUV-Studios:main
base: main-old
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
b446e72
Improved C++ project templates
JaiganeshKumaran d788da7
Move CppWinRT/RuntimeComponent to Desktop fom Neutral
JaiganeshKumaran 47274e9
Remove InitializeComponent from C++/WinRT App's constructor
JaiganeshKumaran 541086a
Avoid capturing this in the UnhandledException handler
JaiganeshKumaran bc09e3d
Add a space between pragma once and include in App.h for consistency
JaiganeshKumaran 1a920cd
Revert removing __has_include check before including g.cpp
JaiganeshKumaran 1b96da8
Merge branch 'main' into main
JaiganeshKumaran 73303ec
Merge branch 'main' into main
JaiganeshKumaran e65b0da
Merge branch 'main' into main
JaiganeshKumaran 24e2202
Fix typo: Desktopy -> Desktop
JaiganeshKumaran File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 0 additions & 4 deletions
4
dev/VSIX/ItemTemplates/Desktop/CppWinRT/BlankWindow/BlankWindow.idl
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,8 @@ | ||
// Copyright (c) Microsoft Corporation and Contributors. | ||
// Licensed under the MIT License. | ||
|
||
namespace $rootnamespace$ | ||
{ | ||
[default_interface] | ||
runtimeclass $safeitemname$ : Microsoft.UI.Xaml.Window | ||
{ | ||
$safeitemname$(); | ||
Int32 MyProperty; | ||
} | ||
} |
10 changes: 5 additions & 5 deletions
10
dev/VSIX/ItemTemplates/Desktop/CppWinRT/BlankWindow/BlankWindow.xaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,14 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<?xml version="1.0" encoding="utf-8" ?> | ||
<Window | ||
x:Class="$rootnamespace$.$safeitemname$" | ||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" | ||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" | ||
xmlns:local="using:$rootnamespace$" | ||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008" | ||
xmlns:local="using:$rootnamespace$" | ||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" | ||
mc:Ignorable="d"> | ||
|
||
<StackPanel Orientation="Horizontal" HorizontalAlignment="Center" VerticalAlignment="Center"> | ||
<Button x:Name="myButton" Click="myButton_Click">Click Me</Button> | ||
</StackPanel> | ||
<Grid> | ||
|
||
</Grid> | ||
</Window> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 0 additions & 4 deletions
4
dev/VSIX/ItemTemplates/Neutral/CppWinRT/BlankPage/BlankPage.idl
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,8 @@ | ||
// Copyright (c) Microsoft Corporation and Contributors. | ||
// Licensed under the MIT License. | ||
|
||
namespace $rootnamespace$ | ||
{ | ||
[default_interface] | ||
runtimeclass $safeitemname$ : Microsoft.UI.Xaml.Controls.Page | ||
{ | ||
$safeitemname$(); | ||
Int32 MyProperty; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
9 changes: 0 additions & 9 deletions
9
dev/VSIX/ItemTemplates/Neutral/CppWinRT/TemplatedControl/TemplatedControl.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 0 additions & 4 deletions
4
dev/VSIX/ItemTemplates/Neutral/CppWinRT/TemplatedControl/TemplatedControl.idl
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,8 @@ | ||
// Copyright (c) Microsoft Corporation and Contributors. | ||
// Licensed under the MIT License. | ||
|
||
namespace $rootnamespace$ | ||
{ | ||
[default_interface] | ||
runtimeclass $safeitemname$ : Microsoft.UI.Xaml.Controls.Control | ||
{ | ||
$safeitemname$(); | ||
Int32 MyProperty; | ||
} | ||
} |
17 changes: 5 additions & 12 deletions
17
dev/VSIX/ItemTemplates/Neutral/CppWinRT/UserControl/UserControl.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 0 additions & 4 deletions
4
dev/VSIX/ItemTemplates/Neutral/CppWinRT/UserControl/UserControl.idl
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,8 @@ | ||
// Copyright (c) Microsoft Corporation and Contributors. | ||
// Licensed under the MIT License. | ||
|
||
namespace $rootnamespace$ | ||
{ | ||
[default_interface] | ||
runtimeclass $safeitemname$ : Microsoft.UI.Xaml.Controls.UserControl | ||
{ | ||
$safeitemname$(); | ||
Int32 MyProperty; | ||
} | ||
} |
10 changes: 5 additions & 5 deletions
10
dev/VSIX/ItemTemplates/Neutral/CppWinRT/UserControl/UserControl.xaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,14 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<?xml version="1.0" encoding="utf-8" ?> | ||
<UserControl | ||
x:Class="$rootnamespace$.$safeitemname$" | ||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" | ||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" | ||
xmlns:local="using:$rootnamespace$" | ||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008" | ||
xmlns:local="using:$rootnamespace$" | ||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" | ||
mc:Ignorable="d"> | ||
|
||
<StackPanel Orientation="Horizontal" HorizontalAlignment="Center" VerticalAlignment="Center"> | ||
<Button x:Name="myButton" Click="myButton_Click">Click Me</Button> | ||
</StackPanel> | ||
<Grid> | ||
|
||
</Grid> | ||
</UserControl> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 changes: 8 additions & 0 deletions
8
dev/VSIX/ProjectTemplates/Desktop/CppWinRT/RuntimeComponent/Class.idl
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
namespace $safeprojectname$ | ||
{ | ||
[default_interface] | ||
runtimeclass Class | ||
{ | ||
Class(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
XAML accepts boxed strings so this change isn't necessary. Can you provide a min repro project for the crash you were encountering with the previous incarnation?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's not a crash, it's a compile error. C++/WinRT
hstring
does not implicitly convert toIInspectable
. It needs to be explicitly done (viawinrt::box_value
). The template won't compile by default.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's correct. However, the change being proposed here is simply from
hstring
toxaml_typename
; the enclosingwinrt::box_value()
call isn't being touched.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, I see. xaml_typename is a C++/WinRT helper that gives a Windows::UI::Xaml::Interop::TypeName for the type. This matches more closely to the C# template (which uses typeof instead of a string), but the runtime behavior is the same (with both the new code and the old code, the runtime will look for
<Style TargetType="$rootnamespace$.$safeitemname$">
)There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The primary benefit of using
xaml_typename<class_type>()
over 'hstring' that I'm aware of is that it simplifies renaming the class. But the argument being made here instead is that there's an error associated with thehstring
variant so that's why I want to dig deeper.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You're right DefaultStyleKey can be set to a boxed hstring as well, it doesn't have to be a TypeName. As an alternative, winrt::name_of could be used instead of winrt::xaml_typename. There are a few differences between the name_of and xaml_typename, for example,
name_of<Windows::Foundation::Point>()
returns "Windows.Foundation.Point" whilexaml_typename<Windows::Foundation::Point>().Name
is "Point". This doesn't matter in this case though.