Windows Mobile development, native C ++ PK. NET Compact framework

Source: Internet
Author: User
Reason

I often hear some questions from people who have just been familiar with Windows Embedded ce and Windows Mobile development. What language is used for Windows Mobile development? C ++ or C #? Does Java work? The following describes the similarities and differences between native C ++ and. NET Compact framework.

 

What is native?

Native is translated into native, and Native uses C, C ++, assembly, and other languages.CodeCompiled, compiled into processor-related binary files (executable files, DLL and other executable files), for executable files can refer to http://en.wikipedia.org/wiki/Portable_Executable. Currently, Windows Embedded ce and Windows Mobile support x86, MIPS, arm, and superh hardware platforms. Because the instruction sets of different platforms are different, executable files cannot support each other on other platforms. Developed using native,ProgramIt does not depend on any other subsystem, such as the. NET Compact framework runtime environment and JVM runtime environment. However, a set of programs must compile different executable files for each hardware platform.

 

What is. NET Compact framework?

Programs Developed Based on. NET Compact framework can be called managed programs and managed code in English. The so-called managed code is to use C #, VB.. NET language. NET Compact framework, compiled into a platform-independent intermediate language (IL) file program. Based on.. NET Compact framework programs will be used during compilation. NET Compact framework basic class library (. NET Compact framework base class libraries, BCL), Bcl provides APIs for applications. The runtime execution engine (EE) is used when the hosting program is running. Bcl and EE are collectively referred to as Common Language Runtime (CLR ). When the hosting program is executed for the first time, CLR will compile the Il file into the binary file (Executable File) of the relevant platform ). This process is called just-in-time (JIT) compilation. With this process, all managed code depends on CLR. Therefore, devices that need to run managed code must install. NET Compact framework.

The figure is from Windows Embedded ce 6.0 fundamentals Chapter 9.

Popularization of native code vs. managed code

The above is a bunch of theoretical things. The following uses a popular but not very relevant example to describe native and managed. Native is translated into native, which is actually authentic, inherent meaning: for example, if you are born to speak Mandarin, you can say that you are a Mandarin native speaker. That is, Mandarin, which is born from the ground. If you want to sell some language-related products, if you translate them into various languages before selling the products, for example, Chinese for domestic sales and English for U.S. sales, translating it into Japanese in Japan is like using native code for development. Native machine code has been generated for each hardware platform during compilation. However, managed code is like a saying in the world. No one in the world speaks a saying in the country or region, but you use the saying in the world to sell your products. For different countries and regions, you can attach a timely translation machine. This translation opportunity translates the world language into a local native language when users use it. This is like the code developed Based on. NET Compact framework. CLR is required for translation and execution. Note that the CLR on different hardware platforms is different. Their functions are to compile il into native machine code, but the machine code on different platforms is different, so the. NET Compact framework is different .. NET Compact framework helps you deal with platform differences. NET Compact framework is a cross-platform program, just like the World Language and the translator, based on. NET Compact framework code can support any platform, provided that Microsoft implements CLR for a specific platform. For example, we all know that Yahoo is actually a language that is about to disappear in the world called Yahoo, then your product can be sold to Yahoo-speaking places without any modification.

Theoretically speaking, native code vs. managed code

Native code

Managed code

Compiled into platform-related machine code Compile to Il (intermediate language)
Compile execution files of different versions for different devices One compilation, various devices running everywhere
No support from other frameworks (compared with. NET Compact framework) CLR support is required, that is, the. NET Compact framework rumtime must be installed.
Allows you to access the APIs and services provided by the system to the maximum extent. Only. NET Compact framework provides services, such as WiFi and Bluetooth ,.. NET Compact framework's Bcl does not provide support, so if you only use. NET Compact framework cannot be used for WiFi or Bluetooth development.
Due to the limitations described above, Microsoft provides P/invoke to access platform-related APIs and COM.
You can use libraries such as MFC, ATL, wtl, and STL for development. You can use the. NET Compact framework's Bcl for development.

 

 

How to Select native code and managed code

After understanding the similarities and differences between native code and managed code, you can select them based on their characteristics and requirements. There is no absolute good or bad, so there is a situation where both platforms exist at the same time.

 

Native code development is relatively slow because it does not support base class libraries of. NET Compact framework. Bcl has made a lot of encapsulation for developers, such as garbage collection, Windows form, and Web Service. Bcl-based developers can focus on business development. Therefore, using. NET Compact framework can save a lot of development time. Today, libraries have more and more influences on languages. Without Ror, ruby may still be a Japanese dialect with unknown names. Father of C ++BjarneStroustrup said that C ++ extensions are more extended in STL and support new features through STL. the syntax of C ++ has not changed much, however, due to the continuous expansion of STL, new vigor is constantly brought. The importance of libraries to a language and developer is visible. In this regard,. NET Compact framework won, but native C ++ can still be remedied through MFC, ATL, wtl, STL. I personally like the wtl processing interface and the extensive use of STL. For more information about wtl, see:

Wtl (Windows Template Library) development under Windows Mobile and Windows WinCE (Windows Embedded CE)

Wtl (Windows Template Library) interface (UI) development under Windows Mobile and Windows WinCE (Windows Embedded CE)

Wtl for Windows Media Player Development in Windows Mobile and WinCE

About how to use wtl in today's plug-ins

 

In Windows Mobile, native C ++ (wtl, MFC, Win32) is used for development. How can I add a menu for the dialog box?

In Windows Mobile, how does one remove the OK button of cstddialogimpl IN THE wtl dialog box?

Use wtl in Windows Mobile for native C ++ development and how to display the wait icon

How to add a hyperlink to wtl development in Windows Mobile and Windows WinCE (Windows Embedded CE)

 

However, the native code execution speed is relatively fast because it is based on. NET Compact framework code has a JIT process. The first execution requires compiling Il to native machine code, and native code itself is a machine code, so native code is much faster.

 

At the same time, native code uses a lot less memory footprint. The footprint used by native code is only related to the memory allocation of your written code. But the Code Based on. NET Compact framework, although a program with almost no function, also needs 1 to 2 MB of memory to start. These memories are used for garbage collection and other purposes.

 

There is a controllable gap between native code and managed code ,. NET Compact framework is. net Framework, encapsulated in part.. NET Framework, but not completely.. NET Framework. Native code has full access to system APIs, services, and platform APIs. net Framework is not fully available ,. NET Compact framework is even less available, so from the perspective of system controllability, there is a gap between native code and managed code. This gap refers to some native code functions, however, managed code cannot implement functions, such as WiFi and Bluetooth. To implement these functions in. NET Compact framework, you must use P/invoke. For more information about P/invoke, see

Use of Win32 api p/invoke under. NET Compact framework

Develop P/invoke tools and website

How to use native C ++ to dynamically load DLL in Windows Mobile

How to encapsulate native DLL provided to. NET Compact framework in Windows Mobile and WinCE (Windows Embedded CE) for calling

Encapsulation of native DLL in Windows Mobile and Windows WinCE (Windows Embedded CE)

Encapsulate native DLL callback functions in Windows Mobile and Windows WinCE (Windows Embedded CE)

Due to the existence of this controllable gap, the smart device framework and 32feet.net libraries of opennetcf appear. These libraries are based on. the program of NET Compact framework encapsulates the call of P/invoke, which reduces the existence of gap. For details about 32feet.net, refer to the 32feet.net-based development of Windows Mobile and PC programs for Broadcom (widcomm) stack Bluetooth devices.Article. Of course, Microsoft is constantly filling this gap ,. NET Compact framework is constantly upgraded, and the gap is getting smaller and smaller, for example. NET Compact Framework 1.0 does not have a serial port,. NET Compact Framework 2.0 has been added. However. the rumtime of NET Compact framework is getting bigger and bigger, and the startup is getting slower and slower. Everything is balanced, and mobile devices are limited by the CPU speed and memory ,. NET Compact framework does not add more functions, the better. Too far away, as the Chinese often say.

Balabala... if there are so many questions, we don't know how to choose them. In fact, they are trade-off (balanced), and there is no absolute truth. We should choose one based on the specific needs and the features of the above native code and managed code. In my own experience, if the speed is fast and the core modules with less memory requirements use native C ++ (generally including non-interface, A pure data processing program and a fully customized interface's GDI Program), used by other modules. NET Compact framework. If a module requires a lot of P/invoke usage, you also need to consider using native C ++ to replace. NET Compact framework. At present, I think the selection is OK.

 

Here, I hope you can understand it. If you have any questions, please reply. Christmas party in the afternoon and happy day.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.