23.01.2018 Views

MICROSOFT_PRESS_EBOOK_PROGRAMMING_WINDOWS_8_APPS_WITH_HTML_CSS_AND_JAVASCRIPT_PDF

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

• A component can contain multiple public activatable classes as well as additional classes that are<br />

internal only. All public classes must reside in the same root namespace, which has the same<br />

name as the component metadata file.<br />

• By default, all public classes in a component are visible to all other languages. A class can be<br />

hidden from JavaScript by applying the WebHostHiddenAttribute (that is, prefix the class<br />

declaration with [Windows.Foundation.Metadata.WebHostHidden] in C# or<br />

[Windows::Foundation::Metadata::WebHostHidden] in C++. This is appropriate for classes that<br />

work with UI (that cannot be shared with JavaScript, such as the whole of the Windows.Xaml<br />

namespace in WinRT) or others that are redundant with JavaScript instrinsics (such as<br />

Windows.Data.Json).<br />

• For some additional structural options, see the following samples in the Windows SDK (all of<br />

which use the WRL; see “Sidebar: The Windows Runtime C++ Template Library” under<br />

“Quickstart #2”):<br />

• Creating a Windows Runtime in-process component sample (C++/CX)<br />

• Creating a Windows Runtime in-process component sample (C#)<br />

• Creating a Windows Runtime EXE component with C++ sample<br />

• Creating a Windows Runtime DLL component with C++ sample<br />

Types<br />

• Within a component, you can use native language types (that is, .NET types and C++ runtime<br />

types). At the level of the component interface (the Application Binary Interface, or ABI), you<br />

must use WinRT types or native types that are actually implemented with WinRT types.<br />

Otherwise those values cannot be projected into other languages. In C++, WinRT types exist in<br />

the Platform namespace, and see Type System (C++/CX); in C#/VB, they exist in the System<br />

namespace, and see .NET Framework mappings of Windows Runtime types.<br />

• A component can use structures created with WinRT types, which are projected into JavaScript<br />

as objects with properties that match the struct members.<br />

• Collections must use specific WinRT types found in Windows.Foundation.Collections, such as<br />

IVector, IMap (and IMapView), and IPropertySet. This is why we’ve often encountered vectors<br />

throughout this book.<br />

• Arrays are a special consideration because they can be passed only in one direction as we saw in<br />

the quickstarts; each must therefore be marked as read-only or write-only. See Passing arrays to<br />

a Windows Runtime component. Arrays also have a limitation in that they cannot be effectively<br />

used with async methods, because an output array will not be transferred back to the caller<br />

when the async operation is complete. We’ll talk more of this in “Implementing Asynchronous<br />

Methods” below.<br />

732

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!