You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
title: Create your first Windows application on Microsoft Visual Studio
2
+
title: Create your first Windows on Arm application using Microsoft Visual Studio
3
3
weight: 2
4
4
5
5
### FIXED, DO NOT MODIFY
@@ -8,79 +8,85 @@ layout: learningpathall
8
8
9
9
## Install Microsoft Visual Studio
10
10
11
-
Visual Studio 2022, Microsoft's Integrated Development Environment (IDE), empowers developers to build high-performance applications across a wide range of platforms. With its robust support for Arm architecture, Visual Studio 2022 opens up exciting possibilities for creating native Arm applications and optimizing existing code for Arm-based devices.
11
+
Visual Studio 2022, Microsoft's Integrated Development Environment (IDE), empowers developers to build high-performance applications for the Arm architecture.
12
12
13
-
You can check out this Microsoft [page](https://learn.microsoft.com/en-us/visualstudio/install/visual-studio-on-arm-devices?view=vs-2022)to learn more about Visual Studio on Arm-powered devices.
13
+
You can learn more about [Visual Studio on Arm-powered devices](https://learn.microsoft.com/en-us/visualstudio/install/visual-studio-on-arm-devices?view=vs-2022)from Microsoft Learn.
14
14
15
15
Visual Studio 2022 offers different editions tailored to various development needs:
16
16
- Community: A free, fully-featured edition ideal for students, open-source contributors, and individual developers.
17
17
- Professional: Offers professional developer tools, services, and subscription benefits for small teams.
18
18
- Enterprise: Provides the most comprehensive set of tools and services for large teams and enterprise-level development.
19
19
20
-
To select the edition best suited to your requirements, compare the features of each on the Visual Studio website: https://visualstudio.microsoft.com/vs/compare/
20
+
To select the best edition for you, refer to [Compare Visual Studio 2022 Editions](https://visualstudio.microsoft.com/vs/compare/).
21
21
22
22
{{% notice Note %}}
23
-
This Learning Path documents an example using Visual Studio 2022 Community edition, you can also use advance edition as well.
23
+
This Learning Path uses Visual Studio Community, but you can also use other editions.
24
24
{{% /notice %}}
25
25
26
-
Visit Viscual Studio [Downloads](https://visualstudio.microsoft.com/downloads/) page and click the download the installer executable.
26
+
Download and install Visual Studio using the [Visual Studio for Windows on Arm](/install-guides/vs-woa/) install guide. Make sure to install C and C++ support and the LLVM compiler.
27
27
28
-
Installation typically takes a few minutes, depending on your network speed. Double-click the downloaded installer and use the default configuration to complete the installation.
28
+
## Create a sample project
29
29
30
-
Learn how to install C/C++ and LLVM support in this [learning path] (https://learn.arm.com/install-guides/vs-woa/).
30
+
You are ready to create a sample Windows on Arm application.
31
31
32
-
## Create a Sample Project
32
+
To keep the example clear and concise, you can create a simple console application.
33
33
34
-
Now, you are ready to create a sample Windows application.
34
+
On the start window, click `Create a new project`.
35
35
36
-
To keep the example clear and concise, we will use the simplest console app here.
37
-
38
-
On the start window, click "Create a new project."
39
36

40
37
41
-
In the "Create a new project" window, select "Console App" give a project name and then click "Next".
38
+
In the `Create a new project` window, select `Console App`, provide a project name, such as `hello-world-1`, and then click `Next`.
39
+
42
40

43
41
42
+
After the project is created, you will see a line of `Hello, world!` code in the newly created C++ file.
44
43
45
-
After the project is created, you will see a line of "Hello, world" code in Program.cs.
46
-
```TypeScript
47
-
Console.WriteLine("Hello, World!");
44
+
```C++
45
+
#include<iostream>
46
+
47
+
intmain()
48
+
{
49
+
std::cout << "Hello World!\n";
50
+
}
48
51
```
49
52
50
-
Microsoft Visual Studio automatically adds the build environment variable for the current hardware's CPU architecture. However, we can still familiarize ourselves with the relevant settings.
53
+
Microsoft Visual Studio automatically configures the build environment for the current hardware's CPU architecture. However, you can still familiarize ourselves with the relevant settings.
54
+
55
+
## ARM64 Configuration Setting
51
56
52
-
## Arm64 Configuration Setting
57
+
Click the `Debug` drop down and select `Configuration Manager...`
53
58
54
-
Go the "Debug" -> "Configuration Manager"
55
59

56
60
57
61
58
-
In the Project contexts platform dropdown, click <New...>. In the New platform dialog box: select `ARM64`.
59
-

62
+
In the `Project contexts` area you see the platform set to `ARM64`.
60
63
64
+

61
65
62
-
{{% notice Note %}}
63
-
Please reference this [learning path](https://learn.arm.com/learning-paths/laptops-and-desktops/win_wpf/how-to-2/) to find more detail about how to configure the Visual Studio platform setting.
64
-
{{% /notice %}}
66
+
Click `Build -> Build Solution` and your application compiles successfully.
65
67
68
+
## Run your first Windows on Arm application
66
69
67
-
Click "Build" -> "Build Solution", your first Windows will compile succesfully.
70
+
Use the green arrow to run the program you just compiled, and you'll see the print statement from your code correctly executed in the console.
68
71
72
+

69
73
70
-
## Run Your First Windows Application
74
+
You can also use the tools provided by Visual Studio to check the compiled executable.
71
75
72
-
Use the green arrow to run the program you just compiled, and you'll see the statement from your code correctly executed in the console.
76
+
The [dumpbin](https://learn.microsoft.com/en-us/cpp/build/reference/dumpbin-reference?view=msvc-170) command-line tool is included with Microsoft Visual Studio. It's used to analyze binary files like executable files (.exe), object files (.obj), and dynamic-link libraries (.dll).
73
77
74
-

78
+
To use `dumpbin` open a Command Prompt with Visual Studio configured by opening Windows search, and looking for `Arm64 Native Tools Command Prompt for VS 2022`. Find and open this application.
75
79
76
-
You can also use the tools provided by Visual Studio to check the compiled executable.
80
+
A new Command Prompt opens. It's the same as the regular Windows Command Prompt with the addition that Visual Studio tools can be run from the prompt.
77
81
78
-
[dumpbin](https://learn.microsoft.com/en-us/cpp/build/reference/dumpbin-reference?view=msvc-170) is a command-line tool included with Microsoft Visual Studio. It's used to analyze binary files like executable files (.exe), object files (.obj), and dynamic-link libraries (.dll).
79
-
In your Windows search, look for "Arm64 Native Tools Command Prompt for VS 2022" and open this program.
82
+
Run the command below with the executable you crated as an argument:
To facilitate explaining the topic, this repository is forked from the original author [here](https://github.com/marcpems/SpinTheCubeInGDI)with some modifications to aid in the following explanations.
26
+
The example repository is forked from the [original GitHub repository](https://github.com/marcpems/SpinTheCubeInGDI)and some minor modifications have been made to aid learning.
21
27
{{% /notice %}}
22
28
23
-
## Quick Introduction
29
+
## Spin the cube introduction
30
+
31
+
In Windows File Explorer, double-click `SpinTheCubeInGDI.sln` to open the project in Visual Studio.
24
32
25
-
Click the SpinTheCubeInGDI.sln to open the project.
26
-
This source code implements a Windows application that renders a spinning 3D cube.
33
+
The source file `SpinTheCubeInGDI.cpp` implements a spinning cube.
27
34
28
-
Four of key components are:
35
+
The four key components are:
29
36
- Shape Generation: Generates the vertices for a sphere using a golden ratio-based algorithm.
30
37
- Rotation Calculation:
31
-
The application uses a rotation matrix to rotate the 3D shape around the X, Y, and Z axes. The rotation angle is incremented over time, creating the animation. This code apply two options to calculate:
32
-
- Multithreading: The application utilizes multithreading to improve performance by distributing the rotation calculations across multiple threads.
33
-
- Arm Performance Libraries: Used for optimized calculations. (Explained in the next session)
34
-
- Drawing: The application draws the transformed vertices of the shapes on the screen, using Windows API.
38
+
The application uses a rotation matrix to rotate the 3D shape around the X, Y, and Z axes. The rotation angle is incremented over time, creating the animation.
39
+
- Drawing: The application draws the transformed vertices of the shapes on the screen, using a Windows API.
35
40
- Performance Measurement: The code measures and displays the number of transforms per second.
36
41
42
+
The code has two options to calculate the rotation:
43
+
44
+
1. Multithreading: The application utilizes multithreading to improve performance by distributing the rotation calculations across multiple threads.
45
+
2. Arm Performance Libraries: The application utilizes optimized math library functions for the rotation calculations.
46
+
47
+
Option 1 is explained below and option 2 is explained on the next page. By trying both methods you can compare and contrast the code and the performance.
48
+
49
+
## Option 1: Multithreading
50
+
51
+
One way to speed up the rotation calculations is to use multithreading.
37
52
38
-
## Calculation Option#1 -- Multithreading
53
+
The multithreading implementation option involves two functions:
39
54
40
-
In this learning path, our focus is on the impact of different Calculation option on performance.
41
-
The multithreading implement on the project involved two of functions:
42
-
- CalcThreadProc():
55
+
- The `CalcThreadProc()` function
43
56
44
-
This function is the entry point for each calculation thread. Each calculation thread waits on its semaphore in semaphoreList.
57
+
This function is the entry point for each calculation thread. Each calculation thread waits on its semaphore in `semaphoreList`.
45
58
46
-
When a thread receives a signal, it calls `applyRotation()` to transform its assigned vertices. The updated vertices are stored in the drawSphereVertecies vector
59
+
When a thread receives a signal, it calls `applyRotation()` to transform its assigned vertices. The updated vertices are stored in the `drawSphereVertecies` vector. The code is shown below:
47
60
48
61
```c++
49
62
DWORD WINAPI CalcThreadProc(LPVOID data)
@@ -70,9 +83,10 @@ The multithreading implement on the project involved two of functions:
70
83
return 0;
71
84
}
72
85
```
73
-
74
-
- applyRotation():
75
-
This function applies the rotation matrix to a subset of the shape's vertices.
86
+
87
+
- The `applyRotation()` function:
88
+
89
+
This function applies the rotation matrix to a subset of the shape's vertices using multiplication. The code is shown below:
76
90
77
91
```c++
78
92
voidapplyRotation(std::vector<double>& shape, const std::vector<double>& rotMatrix, int startPoint, int stride)
@@ -113,23 +127,23 @@ The multithreading implement on the project involved two of functions:
113
127
```
114
128
115
129
116
-
## Build and Test
130
+
## Build and run the application
131
+
132
+
After gaining a general understanding of the project, you can compile and run it.
133
+
134
+
Build the project, and run `SpinTheCubeInGDI.exe`
117
135
118
-
After gaining a general understanding of the project, you can compile it.
119
-
Build the project, and once successful, run `SpinTheCubeInGDI.exe`.
136
+
You will see a simulated 3D sphere continuously rotating.
120
137
121
-
You'll see a simulated 3D sphere continuously rotating. The number in the upper-left corner represents the number of frames per second (FPS). A higher number indicates better performance, and vice versa.
138
+
The number in application represents the number of frames per second (FPS). A higher number indicates better performance.
122
139
123
140

124
141
125
-
On my test machine, the performance generally falls between 3 and 6 FPS, which is unstable.
142
+
Performance varies across various Windows on Arm computers, but on the Lenovo X13s the performance generally falls between 3k and 6k FPS.
126
143
127
-
{{% notice Note %}}
128
-
Performance may vary depending on the hardware and the system load at the time of testing.
129
-
{{% /notice %}}
130
144
145
+
You can use the [Visual Studio profiling tools](https://learn.microsoft.com/en-us/visualstudio/profiling/profiling-feature-tour?view=vs-2022) to observe the dynamic CPU and memory usage while the program is running.
131
146
132
-
You can also use the [profiling tools](https://learn.microsoft.com/en-us/visualstudio/profiling/profiling-feature-tour?view=vs-2022) to observe the dynamic CPU and memory usage while the program is running.
133
147

134
148
135
-
149
+
Continue to the next section to learn how to improve performance using Arm Performance Libraries.
0 commit comments