Windows Phone 8 introduces the ability to use native code to implement Windows Phone. In this section, we explain how you can use C++ in your app, and provide some recommended scenarios.

When to use native code in your app

All Windows Phone 8 apps can use native code but not all apps need to. For many app scenarios, a managed app provides the same features and performance as an app that uses native code. The following are reasons why you may want to use native code in your app.

  • Portability – If you are targeting multiple platforms, it may make sense to implement your core functionality in a native library that can be used on all of the platforms you are targeting.
  • Direct3D graphics – If your app needs to use Direct3D to render graphics to the screen, this must be done using native code.
  • Performance – For some scenarios, you can achieve a performance benefit in large computation tasks by using native code. Note that there is overhead associated with the interop between native and managed code. This overhead may cancel out any performance gains from using native code, so don’t assume that using C++ will automatically increase the performance of your app.

Native code support

Windows Phone 8 supports Visual C++ 2012. This is the full version of C++ that is available on the desktop, and the two versions use the same compiler and IDE. This means that your phone app can reuse existing C and C++ libraries that you have developed for other platforms, in addition to third-party libraries and middleware.

Windows Phone 8 supports a limited set of COM and Win32 APIs that are available on the desktop. For info about which APIs are supported, see Win32 and COM API for Windows Phone 8.

All Windows Phone 8 apps also can use the Windows Phone Runtime, which is a phone-specific implementation of the Windows Runtime, which is used for desktop apps. The Windows Phone Runtime provides infrastructure and an API library. The infrastructure is the core plumbing of the language, including type activation, memory management, a common type system, and a standard programming model that encompasses objects, methods, events, exceptions, and so on. The Windows Phone Runtime library contains phone-specific APIs for features such as speech, managing contacts, location, sensors, networking, and more. In addition, the library supports a subset of the Windows Runtime library that’s available on the desktop. All of these APIs are projected into Visual Basic, C#, and C++ on the phone. For more info about the APIs supported on the phone, see Windows Phone Runtime API.

The Windows Phone Runtime also enables interop between managed and native code. You can add a Windows Phone Runtime component implemented in C++ to your project and then access the objects and methods in the component directly from managed code. Note that there is some overhead cost when using Windows Phone Runtime because of things like reference counting and array bounds checking. For this reason, we recommend that you use it only on the boundary between managed and native. Especially if you are implementing a computation scenario in which performance is key, you should write your computation library in straight C or C++ and then create a Windows Phone Runtime wrapper that can be called from managed code.

Direct3D graphics on Windows Phone

Windows Phone 8 introduces the ability to use Direct3D in your app, and Direct3D code must be written in C++. You can use the XAML and Direct3D app and the Direct3D with XAML app project templates to create hybrid apps in which the UI is defined in XAML with managed (C# or Visual Basic .NET [VB.NET]) code-behind pages. With these apps, a Windows Phone Runtime component contains the native Direct3D code, which renders to the screen within or behind the XAML UI. The Direct3D app project template creates a pure native app that uses no XAML or managed code. Because of this, there are several feature and app model differences between this type of app and a XAML-based app. For guidance on determining which app type is right for your app, see Choosing the right project template for your game for Windows Phone 8.

For info about Direct3D API support on Windows Phone, see Direct3D for Windows Phone 8.

Unsupported native code scenarios

The following uses of native code are not supported for Windows Phone apps.

  • Native code can’t be called from an XNA app.
  • Windows Phone 8 doesn’t support the XAML UI with C++ code-behind app model that is supported for Windows Store apps.
  • Native code can’t be called from Windows Phone OS 7.0 or Windows Phone OS 7.1 apps. Only Windows Phone 8 apps can use this feature.

from http://msdn.microsoft.com/en-US/library/windowsphone/develop/jj681687(v=vs.105).aspx

Native code on Windows Phone 8(转)的更多相关文章

  1. Windows Phone中使用Native Code

    前言      Windows Phone 8 SDK中一个非常有用的特性,就是可以通过Windows Phone Runtime Component (WinPRT)使用C++代码来处理运算量大的任 ...

  2. NDK开发历程(一):android native code的调试方法

    引用:http://www.cnblogs.com/ychellboy/archive/2013/02/22/2922683.html 使用NDK在android上做开发是一件“痛并快乐着”的差事,之 ...

  3. NDK环境搭建(Native Code的编译,不需要Cygwin)

    分类: android2013-06-21 15:49 475人阅读 评论(0) 收藏 举报 Android NDK 目录(?)[-] System and Software Requirements ...

  4. DEPLOYING NATIVE UWP (UNIVERSAL WINDOWS PLATFORM) APPS FOR JAVA DEVELOPERS & PUBLISHING THEM TO THE MICROSOFT STORE

    原文: DEPLOYING NATIVE UWP (UNIVERSAL WINDOWS PLATFORM) APPS FOR JAVA DEVELOPERS & PUBLISHING THEM ...

  5. [Xamarin] 透過Native Code呼叫 JavaScript function (转帖)

    今天我們來聊聊關於如何使用WebView 中的Javascript 來呼叫 Native Code 的部分 首先,你得先來看看這篇[Xamarin] 使用Webview 來做APP因為這篇文章至少講解 ...

  6. 打印发现function toUpperCase() { [native code] }

    var s='hello' undefined s.toUpperCase function toUpperCase() { [native code] } s.toUpperCase() " ...

  7. 不可或缺 Windows Native (25) - C++: windows app native, android app native, ios app native

    [源码下载] 不可或缺 Windows Native (25) - C++: windows app native, android app native, ios app native 作者:web ...

  8. [Cordova] 无法编译Visual Studio项目里Plugin副本的Native Code

    [Cordova] 无法编译Visual Studio项目里Plugin副本的Native Code 问题情景 开发Cordova Plugin的时候,开发的流程应该是: 建立Cordova Plug ...

  9. 优秀开源代码解读之JS与iOS Native Code互调的优雅实现方案

    简介 本篇为大家介绍一个优秀的开源小项目:WebViewJavascriptBridge. 它优雅地实现了在使用UIWebView时JS与ios 的ObjC nativecode之间的互调,支持消息发 ...

随机推荐

  1. ARC机制

    ARC概念及原理 1.了解指针分类 (1)强指针:默认的情况下,所有的指针都是强指针,关键字strong (2)弱指针:_ _weak关键字修饰的指针 声明一个弱指针如下: _ _weak Perso ...

  2. 什么是XMLA-- XML for Analysis

    在我刚开始接触OLAP时,同事就告诉我 XMLA会让他使用更方便. 什么是XMLA? Providers 供应商 ActivePivot Hyperion Essbase IBM Infosphere ...

  3. android Gui系统之SurfaceFlinger(4)---Vsync(1)

    8.Vsync 8.1概论 VSYNC(Vertical Synchronization)是一个相当古老的概念,对于游戏玩家,它有一个更加大名鼎鼎的中文名字—-垂直同步. “垂直同步(vsync)”指 ...

  4. 测试必备技能系列4:如何用SSH向linux服务器上传下载文件

    通过ssh方式,向远程服务器上传文件 非常方便 直接看老徐之前的文章http://www.51testing.com/?uid-497177-action-viewspace-itemid-37054 ...

  5. Java并发之CyclicBarrier 可重用同步工具类

    package com.thread.test.thread; import java.util.Random; import java.util.concurrent.*; /** * Cyclic ...

  6. jquery 基础教程[温故而知新二]

    子曰:“温故而知新,可以为师矣.”孔子说:“温习旧知识从而得知新的理解与体会,凭借这一点就可以成为老师了.“ 尤其是咱们搞程序的人,不管是不是全栈工程师,都是集十八般武艺于一身.不过有时候有些知识如果 ...

  7. Windows10 利用 Docker 配置 TensofFlow 深度学习工具

    TensorFlow 这个不用多介绍了吧,大家都知道,Google的开源深度学习软件库,官网点这里:https://www.tensorflow.org/ 当然这个工具官方支持装在 Ubuntu 和 ...

  8. Linux系统管理命令之权限管理

    对于一个目录来说,x权限:可以cd进去 对于目录: 读:看 执行:进去 写:写操作 rw权限没有意义 umask 022     特殊权限: suid sgid 2种情况:对于文件:类似于suid对于 ...

  9. C#中标准Dispose模式的实现与使用(条目17 实现标准的销毁模式)

    实现了Dispose模式与实现了IDisposable接口的区别就是:IDisposable的实现的可靠性(释放相关资源)要靠编程人员来解决(你确信你从来都一直调用了Dispose(Close)方法吗 ...

  10. 通过url 下载文件

    1.问题简介 通过文件的url,将文件下载到本地.文件存储的位置为:tomcat服务器的文件夹(通过读取properties文件:可看:http://www.cnblogs.com/0201zcr/p ...