- Компоненты среды выполнения Windows Windows Runtime components
- What are the main components of a Computer system?
- What is a computer?
- Components of a Computer system
- 1] Input
- 2] Output
- 3] Processing or System Unit
- 4] Storage
- 5] Communications
- Manage the Component Store
- The Windows component store and WinSxS folder
- Hard links
- Managing the Windows Component Store
- Windows Runtime components with C++/CX
- Casing and naming rules
- JavaScript
- Instantiating the object
- C++/CX built-in types, library types, and Windows Runtime types
- Method that returns a value of built-in type
- Method that returns a custom value struct
- Overloaded Methods
- DateTime
- Collections and arrays
- Passing IVector
- Passing IMap
- Properties
- Delegates and events
- Adding an event listener
- Adding multiple event listeners for one event
- Enums
- Asynchronous methods
- Exceptions
- Debugging tips
Компоненты среды выполнения Windows Windows Runtime components
Компонент среды выполнения Windows — это автономный программный модуль, который можно создать и использовать в качестве источника информации на любом языке среды Windows, включая C#, C++/WinRT, Visual Basic, JavaScript и C++/CX. A Windows Runtime component is a self-contained software module that you can author, reference, and use with any Windows Runtime language (including C#, C++/WinRT, Visual Basic, JavaScript, and C++/CX). Вы можете создать компонент среды выполнения Windows с помощью Visual Studio, а затем использовать его в приложении универсальной платформы Windows (UWP). You can use Visual Studio to create a Windows Runtime component that can be used in your Universal Windows Platform (UWP) app.
Для разработчиков C++ мы рекомендуем использовать C++/WinRT. For C++ developers, we recommend that you use C++/WinRT for new applications. C++/WinRT — это полностью стандартная проекция языка C++17 для API среды выполнения Windows (WinRT), реализованная как библиотека на основе файлов заголовков и предназначенная для предоставления вам первоклассного доступа к современным интерфейсам API Windows. C++/WinRT is an entirely standard modern C++17 language projection for Windows Runtime (WinRT) APIs, implemented as a header-file-based library, and designed to provide you with first-class access to the modern Windows API. Сведения о создании компонента среды выполнения Windows с помощью C++/WinRT см. в статье Создание компонентов среды выполнения Windows с помощью C++/WinRT. To learn how to create a Windows Runtime component using C++/WinRT, see Windows Runtime components with C++/WinRT.
What are the main components of a Computer system?
A computer is nothing without the components or parts inside of it. Many users are taking advantage of what these powerful machines have to offer, yet have no idea what components make them tick. Bear in mind that a computer contains several mechanical, electric, and electronic components are known as hardware.
Do you know what these hardware components are? If not, then continue reading and well explain everything you need to know. But first, let us explain what a computer is before moving forward to the good stuff. Now, bear in mind this won’t be a long article since the information here is pretty simple, but believe us, a lot of computer users have no idea.
What is a computer?
A computer is merely an electronic device that operates under the control of commands stored in its own memory. The instructions here can accept data, and then process that data according to specific rules. Additionally, it can produce results and store these same results for future reference.
Bear in mind that a computer is not only a machine that is powered by Windows 10, but also Linux, macOS, Android, and other operating systems designed only for industrial use. Even modern cars rely heavily on computers to perform.
Components of a Computer system
The 5 the main components of a Computer system are:
- Input
- Output
- Processing Unit
- Storage
- Communications.
Let us take a look at them.
1] Input
The input allows the user to enter information and commands into a computer. A scanner, keyboard, touchscreen, and mouse are the perfect examples of an input device. Interestingly enough, mics have become quite important for inputting data.
Today, it’s possible to add texts in Microsoft Word without ever using a keyboard. Just activate Office Dictation, then speak into your mic to input the data. We can say for certain that it works quite well if words are pronounced correctly. It won’t replace the keyboard completely, but it’s a good alternative when your fingers become too sore to type.
2] Output
When you look at what an Input component is, it should then be very easy to determine what is an Output component. If you have yet to figure it out, well, it’s a hardware component that transports information to one or more people. A computer monitor, printer, projector, and speakers are examples of Output hardware.
As you might have already known, the projector is very similar to a monitor. The main difference is that it projects data onto a hard surface, while a monitor shows the information on a screen.
Additionally, television can also be used as a monitor if it has the right connection. Today, every television with an HDMI connector can act as a monitor.
3] Processing or System Unit
If you’re using a desktop computer, then the System Unit would be the case that contains all the electronic hardware that is used to process data. The primary tool inside of the System Unit is the processor, the brain of your computer. Not only that, but it contains the memory unit, which is also known as the RAM (Random Access Memory). Furthermore, it is also the home of the motherboard, hard drive, cooling unit, and more.
In truth, the system unit is the most important aspect of a consumer-grade computer, at least, for now. Things might change in the future when cloud computing becomes the norm.
4] Storage
OK, so let’s talk a little about storage and what it all means. You see, Storage in a computer is all about recording and retrieving items to and from other storage media. For example, users can store data for future use in the ROM (Read Only Memory), or on a hard drive.
The hard drive is home to the operating system and all files saved on the machine. As for the ROM, well, it is designed to keep software that won’t be modified. Firmware is one such software that is only located on the ROM and nowhere else.
This is why whenever a computer is wiped clean, the firmware stays the same at all times. And this is a good thing for the system and the user in general.
Older computers have a CD drive built-in for various reasons. Most folks would use this drive-bay to add DVDs to watch movies, listen to music, and more. However, a DVD or CD can also be used to store files for future use in the same way as a hard drive. Not as reliable, but possible.
5] Communications
A computer in today’s world is nothing without the ability to communicate with other devices or on the internet. With this ability, then, folks can send and receive data from mobile devices and other computers with ease.
They can even do so over the cloud. An example of this is the use of Windows 10 to send and retrieve Office files from a OneDrive cloud storage account.
The ability to communicate relies on internal hardware components such as Bluetooth and Wi-Fi adapters. But also the USB ports for sending data from the computer to a mobile device, and HDMI for communicating with another screen.
These tools can provide the provides hardware configuration information about your computer easily:
Manage the Component Store
“Why is WinSxS so large?” has been asked by many Windows users. While this question has been discussed in blog posts, this topic goes into a little more details about the concepts behind the component store (specifically the WinSxS folder) and then provides links to topics that highlight ways to better manage the size of the WinSxS folder.
The short answer is that the WinSxS folder isn’t as large as it may appear at first glance because size calculations can include Windows binaries located elsewhere which makes the WinSxS folder seem larger than it really is.
The Windows component store and WinSxS folder
The WinSxS folder is located in the Windows folder, for example c:\Windows\WinSxS. It’s the location for Windows Component Store files. The Windows Component Store is used to support the functions needed for the customization and updating of Windows. Here are some examples of how the Windows Component Store files are used:
Using Windows Update to install new component versions. This keeps systems secure and up-to-date.
Enabling or disabling Windows features.
Adding roles or features using Server Manager.
Moving systems between different Windows Editions.
System recovery from corruption or boot failures
Uninstalling problematic updates
Running programs using side-by-side assemblies
The Windows Component Store was first introduced in WindowsВ XP to support side by side assemblies. Beginning in WindowsВ Vista, the component store was enhanced to track and service all of the components that make up the operating system. Those different operating system components track objects such as files, directories, registry keys, and services. Specific versions of components are then collected together into packages. Packages are used by Windows Update and DISM to update Windows. The components and packages used in a Windows installation are processed by the Windows Component Store. Determining the size of the Windows Component Store is complicated by the fact that many of the files are used by Windows from directories outside the Windows Component Store using a technique known as hard linking. In such cases, the files from a component version appear both inside and outside the Windows Component Store. By using hard linking Windows is able to appear to keep multiple copies of the same file without actually taking the added space for multiple copies.
Hard links
A hard link is a file system object which allows two files to refer to the same location on disk. This means that more than one file can refer to the same data and changes to that data in one file are reflected in the other files. This complicates notions of directory size as can be seen using the following example:
Directory A has three files: 1.txt, 2.txt, and 3.txt
Directory B has one file: 4.txt
Files 1.txt and 2.txt are hard linked together and contain 1MB of data.
Files 3.txt and 4.txt are also hard linked together and contain 2MB of data.
In this example, you can see that the hard links enable multiple files to refer to the same set of data.
Now what is the size of directory A?
The answer depends on what you plan to do with directory A:
If you read the files in the directory A then the size of all the files that are read is the sum of each file size. In this example, that would be 4 MB.
If you copy all the files from directory A to a new location, then the amount of data copied is the sum of all data hard linked from the files. In this example, that would be 3 MB.
If you are trying to free up space by deleting the directory A, you will only see a reduction in size for the files that are hard linked only by directory A. In this example, this amounts to a savings of 1 MB.
Back to the question of how much space is used by the Windows Component Store, and specifically the WinSxS folder. The third answer in the directory A example, most closely matches how much extra space is used. Files hard linked to the rest of the system are required for system operations, so they should not be counted, and files hard linked to multiple locations within the component store should only have the size stored on disk counted.
Managing the Windows Component Store
You can use new features in Windows 8.1 and WindowsВ Server 2012 R2 to manage the Windows Component Store:
Windows Runtime components with C++/CX
This topic exists to help you maintain your C++/CX application. But we recommend that you use C++/WinRT for new applications. C++/WinRT is an entirely standard modern C++17 language projection for Windows Runtime (WinRT) APIs, implemented as a header-file-based library, and designed to provide you with first-class access to the modern Windows API. To learn how to create a Windows Runtime component using C++/WinRT, see Windows Runtime components with C++/WinRT.
This topic shows how to use C++/CX to create a Windows Runtime component—a component that’s callable from a Universal Windows app built using any Windows Runtime language (C#, Visual Basic, C++, or Javascript).
There are several reasons for building a Windows Runtime component in C++.
- To get the performance advantage of C++ in complex or computationally intensive operations.
- To reuse code that’s already written and tested.
When you build a solution that contains a JavaScript or .NET project, and a Windows Runtime component project, the JavaScript project files and the compiled DLL are merged into one package, which you can debug locally in the simulator or remotely on a tethered device. You can also distribute just the component project as an Extension SDK. For more information, see Creating a Software Development Kit.
In general, when you code your C++/CX component, use the regular C++ library and built-in types, except at the abstract binary interface (ABI) boundary where you are passing data to and from code in another .winmd package. There, use Windows Runtime types and the special syntax that C++/CX supports for creating and manipulating those types. In addition, in your C++/CX code, use types such as delegate and event to implement events that can be raised from your component and handled in JavaScript, Visual Basic, C++, or C#. For more information about the C++/CX syntax, see Visual C++ Language Reference (C++/CX).
Casing and naming rules
JavaScript
JavaScript is case-sensitive. Therefore, you must follow these casing conventions:
- When you reference C++ namespaces and classes, use the same casing that’s used on the C++ side.
- When you call methods, use camel casing even if the method name is capitalized on the C++ side. For example, a C++ method GetDate() must be called from JavaScript as getDate().
- An activatable class name and namespace name can’t contain UNICODE characters.
The .NET languages follow their normal casing rules.
Instantiating the object
Only Windows Runtime types can be passed across the ABI boundary. The compiler will raise an error if the component has a type like std::wstring as a return type or parameter in a public method. The Visual C++ component extensions (C++/CX) built-in types include the usual scalars such as int and double, and also their typedef equivalents int32, float64, and so on. For more information, see Type System (C++/CX).
C++/CX built-in types, library types, and Windows Runtime types
An activatable class (also known as a ref class) is one that can be instantiated from another language such as JavaScript, C# or Visual Basic. To be consumable from another language, a component must contain at least one activatable class.
A Windows Runtime component can contain multiple public activatable classes as well as additional classes that are known only internally to the component. Apply the WebHostHidden attribute to C++/CX types that are not intended to be visible to JavaScript.
All public classes must reside in the same root namespace which has the same name as the component metadata file. For example, a class that’s named A.B.C.MyClass can be instantiated only if it’s defined in a metadata file that’s named A.winmd or A.B.winmd or A.B.C.winmd. The name of the DLL is not required to match the .winmd file name.
Client code creates an instance of the component by using the new (New in Visual Basic) keyword just as for any class.
An activatable class must be declared as public ref class sealed. The ref class keyword tells the compiler to create the class as a Windows Runtime compatible type, and the sealed keyword specifies that the class cannot be inherited. The Windows Runtime does not currently support a generalized inheritance model; a limited inheritance model supports creation of custom XAML controls. For more information, see Ref classes and structs (C++/CX).
For C++/CX, all the numeric primitives are defined in the default namespace. The Platform namespace contains C++/CX classes that are specific to the Windows Runtime type system. These include Platform::String class and Platform::Object class. The concrete collection types such as Platform::Collections::Map class and Platform::Collections::Vector class are defined in the Platform::Collections namespace. The public interfaces that these types implement are defined in Windows::Foundation::Collections Namespace (C++/CX). It is these interface types that are consumed by JavaScript, C# and Visual Basic. For more information, see Type System (C++/CX).
Method that returns a value of built-in type
Method that returns a custom value struct
To pass user-defined value structs across the ABI, define a JavaScript object that has the same members as the value struct that’s defined in C++/CX. You can then pass that object as an argument to a C++/CX method so that the object is implicitly converted to the C++/CX type.
Another approach is to define a class that implements IPropertySet (not shown).
In the .NET languages, you just create a variable of the type that’s defined in the C++/CX component.
Overloaded Methods
A C++/CX public ref class can contain overloaded methods, but JavaScript has limited ability to differentiate overloaded methods. For example, it can tell the difference between these signatures:
But it can’t tell the difference between these:
In ambiguous cases, you can ensure that JavaScript always calls a specific overload by applying the Windows::Foundation::Metadata::DefaultOverload attribute to the method signature in the header file.
This JavaScript always calls the attributed overload:
The .NET languages recognize overloads in a C++/CX ref class just as in any .NET class.
DateTime
In the Windows Runtime, a Windows::Foundation::DateTime object is just a 64-bit signed integer that represents the number of 100-nanosecond intervals either before or after January 1, 1601. There are no methods on a Windows:Foundation::DateTime object. Instead, each language projects the DateTime in the way that is native to that language: the Date object in JavaScript and the System.DateTime and System.DateTimeOffset types in .NET.
When you pass a DateTime value from C++/CX to JavaScript, JavaScript accepts it as a Date object and displays it by default as a long-form date string.
When a .NET language passes a System.DateTime to a C++/CX component, the method accepts it as a Windows::Foundation::DateTime. When the component passes a Windows::Foundation::DateTime to a .NET method, the Framework method accepts it as a DateTimeOffset.
Collections and arrays
Collections are always passed across the ABI boundary as handles to Windows Runtime types such as Windows::Foundation::Collections::IVector^ and Windows::Foundation::Collections::IMap^. For example, if you return a handle to a Platform::Collections::Map, it implicitly converts to a Windows::Foundation::Collections::IMap^. The collection interfaces are defined in a namespace that’s separate from the C++/CX classes that provide the concrete implementations. JavaScript and .NET languages consume the interfaces. For more information, see Collections (C++/CX) and Array and WriteOnlyArray (C++/CX).
Passing IVector
The .NET languages see IVector as IList .
Passing IMap
The .NET languages see IMap and IDictionary .
Properties
A public ref class in C++/CX component extensions exposes public data members as properties, by using the property keyword. The concept is identical to .NET properties. A trivial property resembles a data member because its functionality is implicit. A non-trivial property has explicit get and set accessors and a named private variable that’s the «backing store» for the value. In this example, the private member variable _propertyAValue is the backing store for PropertyA. A property can fire an event when its value changes, and a client app can register to receive that event.
The .NET languages access properties on a native C++/CX object just as they would on a .NET object.
Delegates and events
A delegate is a Windows Runtime type that represents a function object. You can use delegates in connection with events, callbacks, and asynchronous method calls to specify an action to be performed later. Like a function object, the delegate provides type-safety by enabling the compiler to verify the return type and parameter types of the function. The declaration of a delegate resembles a function signature, the implementation resembles a class definition, and the invocation resembles a function invocation.
Adding an event listener
You can use the event keyword to declare a public member of a specified delegate type. Client code subscribes to the event by using the standard mechanisms that are provided in the particular language.
This example uses the same C++ code as for the previous properties section.
In the .NET languages, subscribing to an event in a C++ component is the same as subscribing to an event in a .NET class:
Adding multiple event listeners for one event
JavaScript has an addEventListener method that enables multiple handlers to subscribe to a single event.
In C#, any number of event handlers can subscribe to the event by using the += operator as shown in the previous example.
Enums
A Windows Runtime enum in C++/CX is declared by using public class enum; it resembles a scoped enum in standard C++.
Enum values are passed between C++/CX and JavaScript as integers. You can optionally declare a JavaScript object that contains the same named values as the C++/CX enum and use it as follows.
Both C# and Visual Basic have language support for enums. These languages see a C++ public enum class just as they would see a .NET enum.
Asynchronous methods
To consume asynchronous methods that are exposed by other Windows Runtime objects, use the task Class (Concurrency Runtime). For more information, see and Task Parallelism (Concurrency Runtime).
To implement asynchronous methods in C++/CX, use the create_async function that’s defined in ppltasks.h. For more information, see Creating Asynchronous Operations in C++/CX for UWP apps. For an example, see Walkthrough of creating a C++/CX Windows Runtime component, and calling it from JavaScript or C#. The .NET languages consume C++/CX asynchronous methods just as they would any asynchronous method that’s defined in .NET.
Exceptions
You can throw any exception type that’s defined by the Windows Runtime. You cannot derive custom types from any Windows Runtime exception type. However, you can throw COMException and provide a custom HRESULT that can be accessed by the code that catches the exception. There’s no way to specify a custom Message in a COMException.
Debugging tips
When you debug a JavaScript solution that has a component DLL, you can set the debugger to enable either stepping through script, or stepping through native code in the component, but not both at the same time. To change the setting, select the JavaScript project node in Solution Explorer and then choose Properties, Debugging, Debugger Type.
Be sure to select appropriate capabilities in the package designer. For example, if you are attempting to open an image file in the user’s Pictures library by using the Windows Runtime APIs, be sure to select the Pictures Library check box in the Capabilities pane of the manifest designer.
If your JavaScript code doesn’t seem to be recognizing the public properties or methods in the component, make sure that in JavaScript you are using camel casing. For example, the LogCalc C++/CX method must be referenced as logCalc in JavaScript.
If you remove a C++/CX Windows Runtime component project from a solution, you must also manually remove the project reference from the JavaScript project. Failure to do so prevents subsequent debug or build operations. If necessary, you can then add an assembly reference to the DLL.