通過Windows(Phone) Runtime Component來分享你的代碼

來源:互聯網
上載者:User
What
is a Windows Runtime Component?

A Windows Runtime Component, sometimes referred to as a 3rd-party Windows Runtime Component, is a component you build to expose functionality to all supported languages. By using the Windows Runtime, which is supported on Windows Phone 8 and Windows 8, you
can create components and call them in a simple and natural way from the language of your choice. The component is built using the Windows Runtime Component template in Visual Studio. Its functionality is output as a .winmd file, which contains the metadata
needed to project the functionality automatically into C#, C++, VB and JavaScript.

When
to use a Windows Runtime Component when building an app for Windows Phone 8 and Windows 8 

The following list describes when you should consider sharing functionality of your app in Windows Runtime Component.

  • Harnessing the power of C++(駕馭C++強大的力量的時候): If your app carries out computationally intensive operations, you might opt to write that code in C++ to achieve optimal performance. If the code that uses this functionality
    is written in C# or VB, you can package the functionality as a Windows Runtime Component and call the component from your managed code.

  • Crossing language boundaries(跨語言編程的時候): In general, using a Windows Runtime Component is a great way to expose your code to all supported languages. This is not necessary if your app is written in one language
    and you don’t intend to expose any of your functionality to other languages. Instead you can compose your app of regular class libraries, Portable Class Libraries or, depending on the size and complexity of your app, just write the whole app in the same project.

  • Using Direct3D, Win32 or COM APIs(使用系統提供的只能使用C++調用的介面的時候): Windows Phone 8 delivers native API to enable powerful gaming scenarios, native networking and access to camera API from native code. To use these
    API from managed code, you can wrap this functionality in a Windows Runtime Component. For more info, see Supported
    Win32 APIs for Windows Phone 8 and Games for Windows Phone.

  • Using 3rd party libraries(使用第三方庫的時候): In the past, it was difficult to consume a 3rd-party library, written in one language, if your app written in another language. With Windows Runtime Components, it is possible
    to grab a library, wrap it in a Windows Runtime Component and expose the functionality to your app written in any supported language.

The preceding list is some of the scenarios where writing a Windows Runtime Component is a very useful way of sharing code. However, a Windows Runtime Component is not a standard DLL or assembly. There are very specific requirements you must follow when creating
a Windows Runtime Component. These requirements include using only allowed data types, handling collections, creating only sealed classes and many more. Visual Studio will help at compile time, and indicate clearly when something goes wrong.

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.