.NET Compact Framework programming
Release date:
10/21/2004
| Update Date: 10/21/2004
Wei-meng lee
Microsoft .NET Compact Framework is part of the .NET Framework, designed to be operated in mobile devices such as mobile phones, personal digital assistants (PDAs) and embedded devices). It contains subsets of class libraries in the .NET Framework, and also contains a proprietary class designed to run on it. With the advantages of familiarity .NET Framework, developers are now able to quickly create mobile applications using Visual Studio .NET development tools. In this article, wei-meng lee introduces you how to create mobile applications using .NET Compact Framework and Visual Studio .NET 2003.
Different service layers that make up the mobile application are shown in FIG.
figure 1
The bottom layer is the hardware that the operating system resides. It can run on the Intel Xscale processor or the older Strongarm processor. The operating system is operating on the hardware, such as Windows CE 2.x, 3.0, or the latest Windows CE .NET.
Operating system and hardware together constitute a platform. Some examples of the platform include Pocket PC and Pocket PC 2002. The application developed before .NET Compact Framework directly accesses the service provided by the operating system, so they are called the native application. Application Domain Host itself is a native application, its main job is to carry the Common Language Runtime (CLR). The CLR is the .NET Compact Framework class library.
System Requirements
To develop applications using .NET Compact Framework, you need to install Visual Studio .NET 2003. Visual Studio .NET 2003 offers two modes to test your smart device application - use emulation programs or actual devices.
In Visual Studio .NET 2003, the .NET Compact Framework application is called a smart device application. Smart device applications can run on the Pocket PC and Windows CE .NET platform.
Use simulation programs
The easiest way to develop and test smart device applications is to use emulation programs. Visual Studio .NET 2003 provides two simulation programs - a platform for simulating the Windows CE .NET platform, a platform for simulating the Pocket PC 2002. Depending on the product documentation, each emulator requires an additional 64MB RAM on the development machine. From my experience, you need a medium speed CPU and a large amount of memory. I recommend 256MB RAM. Of course, if you have 512MB or 1GB RAM, it will be very helpful to accelerate the development process.
The Simulation of Visual Studio .NET is the actual implementation of the Pocket PC (or Windows CE .NET) operating system, which compiles to run on the X86 platform. This is different from the simulation program, and analog programs are usually a Windows application that imitates the device behavior.
For hardware emulation, the emulator supports two serial ports and a parallel port. These ports can be mapped to the development machine.
Use actual equipment
For applications that utilize special hardware features (such as Bluetooth), Visual Studio .NET 2003 allows you to test applications on actual devices. In order to test on the actual device, you need to establish a connection with the device (via a USB or serial cable). It also requires Microsoft ActiveSync 3.5 so that the application can be copied to the device for testing. By using the debugger in Visual Studio .NET 2003, you can step-by-step code, even if the application is deployed on the device. This is very helpful because it enables debugging applications in real time.
Testing applications on actual devices makes it possible to find out performance issues when using emulation program testing.
Supported language and platform
The first version of the .NET Compact Framework in Visual Studio .NET 2003 only supports Visual Basic .NET and C # languages. Although .NET Framework supports more than 30 languages, it is limited to both languages in .NET Compact Framework. However, this is really not a big problem, because most developers are familiar with Visual Basic .NET and / or C #, and the similarities between these two languages are more than different points.
For the initial version of the .NET Compact Framework, the smart device application can perform on the following platforms:
• Pocket PC • PCKET PC 2002 • Pocket PC 2002 Phone Edition • Windows CE .NET 4.1 and higher
Although Pocket PC and Pocket PC 2002 are based on Windows CE 3.0 operating systems, .NET Compact Framework cannot run on devices with Windows CE 3.0 or lower OS (such as Handheld PC 2000).
Surprisingly, the first version of .NET Compact Framework does not support the recommended Smartphone 2002 platform. But according to Microsoft's statement, you are expected to see support for this platform in the next version of .NET Compact Framework.
Take Pocket PC as an example
Now put all the background knowledge, I will build a smart device application using Visual Studio .NET 2003.
To create a smart device application, you can start Visual Studio .NET 2003 and create a new project by clicking File | New Project.
Select the desired language in "Project Types and Smart Device Application" under Templates "(I use Visual Basic .NET) (see Figure 2).
figure 2
Click "OK" button.
The system will prompt to select the target platform of the application - Pocket PC or Windows CE. In addition, there are 5 available project types:
• Windows Application - Applications for developing GUI features. • Class Library - The class library used to develop used in smart device applications. • Non-Graphical Application - It is used to create an application that does not require a user interface. It is usually referred to as an application running in the background. • Console Application - This option is only available for Windows CE .NET platforms. It creates a application running in a Windows CE .NET console. • Empty Project - It is used to create a new project that does not contain any files.
For my example, I will create a Windows application for the Pocket PC platform (see Figure 3). image 3
Click "OK" to complete the wizard.
Selecting Windows CE as a platform will display the Console Application project type. The Non-Graphical Application project type will not be displayed.
Now you will see familiar IDEs for developing .NET applications (see Figure 4).
Figure 4
Windows control in .NET CF
The toolbox in the smart device application project contains various controls that can be used in smart device applications. (See Figure 5).
Figure 5
Table 1 lists the controls available in the .NET Compact Framework.
Table 1. .NET Compact Framework controls in LabelTextBoxMainMenuRadioButtonComboBoxListViewTabControlHScrollBarDomainUpDownNumericUpDownTrackBarProgressBarCheckboxListboxInput PanelDataGridContextMenuToolBarOpenFileDialogSaveFileDialogPictureBoxPanelVScrollBarTimerStatusBarButtonTreeViewImageList
Design form
First, drag and drop the following controls into the form (see Figure 6):
Figure 6
• Label • TextBox • Button
Double-click the "OK" button to call the "Code" window.
I will add a line in the Button1_Click event to display a message box when clicking the "OK" button. (See Figure 7).
Figure 7
Msgbox ("Hello," TextBox1.text, _
MsgboxStyle.exclamation, "Hello Pocket PC")
If you are familiar with the use .NET Framework to develop Windows applications, you should feel very kind to the development of smart device applications.
Test and debug application
The simplest and fastest way to test the application is to use the simulation program. The simulation program simulates actual devices on the PC without the need to purchase actual equipment for testing. Visual Studio .NET 2003 comes with two simulation procedures: Pocket PC 2002 for Pocket PC applications and Windows ce.net for Windows CE applications. On the Device toolbar, you can choose to test your application using emulation or actual devices. (See Figure 8).
Figure 8
Use simulation programs
The Pocket PC emulation provides virtual representation of a typical Pocket PC hardware configuration. The application running on the emulator accesses the CPU and memory via the emulation program. For this reason, the application runs in the simulation program is usually slower than running on the actual device.
Depending on the target platform, two different simulation programs can be activated by pressing F5 when debugging the application.
The Pocket PC 2002 simulation program simulates the actual device of the Pocket PC 2002 platform. (See Figure 9).
Figure 9
The Windows CE .NET emulation program simulates the actual device running the Windows CE .NET operating system. (See Figure 10).
Figure 10
When you first debug your application, Visual Studio .NET copies all relevant .NET Compact Framework assemblies into the emulator (see Figure 11).
Figure 11
It first copies the executables in the current project to the device and then copy two CAB files and installed on the emulator (or device): Netcf.core.ppc3.x86.cab and system_sr_enu.cab. You can check if the two CAB files have been successfully installed (see Figure 12), the method is to click on: Start | Settings | System | REMOVE Program. These two assemblies occupy a total of 1476KB of memory.
Figure 12
Manual activation simulation program
When you use the emulation to run your smart device application in Visual Studio .NET 2003, the emulator starts automatically. However, sometimes you want to start the simulation program without using Visual Studio .NET 2003. If so, you can manually activate the emulator, run it as a separate application.
The simulation program is located in the directory below: C: / Program Files / Microsoft Visual Studio .NET 2003 / CompactFrameworksdk / ConnectionManager / bin.
Emulator.exe application supports these options:
• / Video - Set the resolution and bit depth of the Emulator for Windows CE display. The format must be
To start the Emulator for Pocket PC 2002, you can locate the subdirectory where the emulator is located and the following commands are issued:
Start Emulator / CeImage
Images / PocketPC / 2002/1033 / PPC2002.BIN
/ Video 240x320x16
For Windows CE .NET Web Pad emulators, you can use the following command:
Start Emulator / CeImage
Images / Windowsce / WebPad / 1033 / WCE4WEBPAD.BIN
Note that I use the start command to activate the emulator. Use the start command to run the emulation and return the control to the command prompt immediately.
Reset simulation program
Resetting the actual equipment is very simple - Most equipment has a reset button at the bottom of the device. But for the simulation program, you have two options:
• Soft Reset - Restart the emulation program. The emulator will keep all previous settings. • Hard reset - restart the emulator and restore the emulator to its initial state. All installed programs are lost. Especially in the next time you run the application from Visual Studio .NET 2003, you need to reinstall the .NET Compact Framework assembly.
Resetting the emulation program is for reasons. I will introduce some common problems in the "Some Common Error" section.
Use actual equipment
Although it is always useful in the development phase emulation program, as long as there is an opportunity to measure an application on practical devices. Testing on actual devices typically discovers performance issues (it is possible to run well on a powerful desktop computer, but is it suitable for running on a slower mobile device?) And availability issues (type text in the emulator It is easy, but this is really a pain on the actual device!).
To test using the actual device, simply change the device options in the Device toolbar to "Pocket PC Device". You also need to connect the Pocket PC to your computer using ActiveSync. If the older version of .NET Compact Framework is installed on the device, you need to delete it from the device. Older versions of the frame will result in the deployment of the current project failed. You can uninstall .NET Compact Framework by positioning to START | Settings | System | Remove Programs.
The installation process is very similar to the simulation program, but there is a payable exception. Since my IPAQ 3870 Pocket PC is using an ARM processor, it is not copy netcf.core.ppc3.x86.cab, but replicates Netcf.core.ppc3.Arm.cab.
Test application
Let us now test this application using the Pocket PC 2002 emulator program. When the default Form1 is loaded, enter a name and click the "OK" button in the text box. A message box that displays a message should be seen as shown in Figure 13.
Figure 13
Some common mistakes
In the process of learning the examples in this article, you may have some problems in your smart device application project. Below are two common errors you might encounter, and how to solve them:
• The device is not connected. Typically, you will see this error message when you try to deploy your application to your actual device. A very common reason is that your device does not connect to the development machine via ActiveSync. Although the device may be physically connected, ActiveSync has not seen it. In this case, you can disconnect the device and connect it again. You may need a reset device or to ensure that the USB (or serial) port on the machine is working properly. • Document sharing conflict. This is another common mistake you may encounter, especially if you have successfully run your app on the emulator or device. Subsequently run the same application may display this message. This will happen when the application is not properly exited because some reason is not properly exited, and you try to run the application again (Visual Studio .NET needs to re-copy the EXE file) Happening. In this case, the reset device is likely to resolve this issue. For the simulation program, first try soft reset to see if the problem will disappear; if it fails, use hard retrofit. If all this failed, restart Visual Studio .NET and run the application again.