ProductName RSS Reader v1.0

Figure 18-30

That's it! Right-click on the SmartDeviceCab1 project name in Solution Explorer and select Build. You can find the CAB file located in the Release folder of the SmartDeviceCab1 project (see Figure 18-31).

Figure 18-31

Now you can distribute the CAB file to your customers using various media such as FTP, web hosting, email, and so on. When the user clicks on the RSSReader CAB file in File Explorer (on the device; see Figure 18-32), the application will ask if he wants to install it onto the device, or onto the storage card (if available).

Figure 18-32

When the application is installed, the RSS Reader shortcut is in the Start menu (see Figure 18-33).

Figure 18-33

Creating a Setup Application

Although you can deploy CAB files directly to your users, you might want to use a more user-friendly way using the traditional setup application that most Windows users are familiar with — users simply connect their devices to their computers and then run a setup application, which then installs the application automatically on their devices through ActiveSync.

Creating a setup application for a Windows Mobile application is more involved than for a conventional Windows application because you have to activate ActiveSync to install it. Figure 18-34 shows the steps in the installation process.

Figure 18-34

First, the application containing the CAB files (and other relevant files) must be installed on the user's computer. Then ActiveSync needs to install the application onto the user's device.

The following sections detail how to create an MSI file to install the application onto the user's computer and then onto the device.

Creating the Custom Installer

The first component you will build is the custom installer that will invoke ActiveSync to install the application onto the user's device. For this, you will use a Class Library project.

Add a new project to your current solution by going to File→Add→New Project. Select the Windows project type and select the Class Library template. Name the project RSSReaderInstaller (see Figure 18- 35). Click OK.

Figure 18-35

Delete the default Class1.cs file and add a new item to the project. In the Add New Item dialog, select the Installer Class template, and name the file RSSReaderInstaller.cs (see Figure 18 -36).

Figure 18-36

Add two references to the project: System.Configuration.Install and System.Windows.Forms (see Figure 18-37).

Figure 18-37

Switch to the code view of the RSSReaderInstaller.cs file and import the following namespaces:

using Microsoft.Win32;

using System.IO;

using System.Diagnostics;

using System.Windows.Forms;

Within the RSSReaderInstaller class, define the INI_FILE constant. This constant holds the name of the .ini file that will be used by ActiveSync for installing the CAB file onto the target device.

namespace RSSReaderInstaller {

 [RunInstaller(true)]

 public partial class RSSReaderInstaller : Installer {

  const string INI_FILE = @'setup.ini';

In the constructor of the RSSReaderInstaller class, wire the AfterInstall and Uninstall events to their corresponding event handlers:

public RSSReaderInstaller() {

 InitializeComponent();

 this.AfterInstall += new

  InstallEventHandler(RSSReaderInstaller_AfterInstall);

 this.AfterUninstall += new

  InstallEventHandler(RSSReaderInstaller_AfterUninstall);

}

void RSSReaderInstaller_AfterInstall(object sender, InstallEventArgs e) {

}

void RSSReaderInstaller_AfterUninstall(object sender, InstallEventArgs e) {

}

The AfterInstall event is fired when the application (CAB file) has been installed onto the user's computer. Similarly, the AfterUninstall event fires when the application has been uninstalled from the user's computer.

When the application is installed on the user's computer, you use Windows CE Application Manager (CEAPPMGR.EXE) to install the application onto the user's device.

The Windows CE Application Manager is installed automatically when you install ActiveSync on your computer.

To locate the Windows CE Application Manager, define the following function named GetWindowsCeApplicationManager():

private string GetWindowsCeApplicationManager() {

 //---check if the Windows CE Application Manager is installed---

 string ceAppPath = KeyExists();

 if (ceAppPath == String.Empty) {

  MessageBox.Show('Windows CE App Manager not installed',

Вы читаете C# 2008 Programmer's Reference
Добавить отзыв
ВСЕ ОТЗЫВЫ О КНИГЕ В ИЗБРАННОЕ

0

Вы можете отметить интересные вам фрагменты текста, которые будут доступны по уникальной ссылке в адресной строке браузера.

Отметить Добавить цитату