In Part-5 of this Windows Embedded Compact 7 (Compact 7) getting started series, we will work through the steps to develop a Compact 7 application in native code, using Visual C++.

Note:

The Compact 7 getting started series consist of 9 different articles, covering the following subjects:

1.        Introduction.

2.        Development Environment & Tools.

3.        Develop a Compact 7 OS Design.

4.        Develop Managed Code Application for Compact 7.

5.        Develop Native Code Application for Compact 7.

6.        Develop SQL Compact Database Application for Compact 7.

7.        Develop Silverlight for Windows Embedded Application for Compact 7.

8.        Debug and Remote Tools.

9.        Deploy OS Runtime to Target Device for Distribution.

Refer to Part-1 (introduction) for more information.

    http://bit.ly/KNDCiu

Prerequisites:

To work through the exercises in this guide, we need to have the following:

·         Development PC with Visual Studio 2008 with service pack 1

(Visual Studio 2008 Express does not support application development for Compact 7.)

·         Successfully compiled a Compact 7 OS image and deploy the image to a target device, to support managed code application, which include the following components:

o   CAB File Installer/Uninstaller

o   Core Connectivity framework files

·         Generated an SDK from the same OS design that produced the OS runtime image for the target device.

·         Installed the MyCompact7_SDK to the development PC.

·         Both the development PC and the target device are connected to the same LAN.

Target Device:  eBox-3300MX

The exercise in this guide is created using an eBox-3300MX as the target device.  Refer to the following URL for more information about the eBox-3300MX:

http://www.embeddedpc.net/eBox3300MX/

Alternative Target Device:  Virtual PC

Using a Virtual PC as target device, we can work through the same exercise in this guide.  To do so, an OS runtime image generated from the OS design created using the Virtual PC board support package (BSP) is needed, along with the SDK generated from the same OS design.

Develop Native Code Application

The main objective for this getting started series is to provide simple and easy to understand information, with step-by-step illustration where possible, to help developer new to Compact 7 to become familiar with the development environment and tools quickly.

To avoid confusion and deliver easy to follow contents, a simple “Hello-world” application is used to show the steps to develop a native code application for Compact 7.

New Smart Device Native Code Application

Work through the following steps to create a native code application for Compact 7:

1.       From the VS2008 File menu, select New and click on Project to bring up the new project wizard, as shown in Figure 1.

Fig-01

Figure 1

2.       On the left pane, expand the Visual C++ node.

3.       On the right pane, select the Win32 Smart Device Project template.

4.       Enter Compact7NativeApp as the project name.

5.       Enter C:\Lab.Compact7 as the location for the project.

Note:

You can choose a different folder for the project other than C:\Lab.Compact7.

6.       Click OK to continue and bring up the Win32 Smart Device Project Wizard screen, as shown in Figure 2.

Fig-02

Figure 2

7.       Click Next to continue and bring up the Platforms selection screen, as shown in Figure 3.

Fig-03

Figure 3

8.       From the Selected SDKs pane on the right, select Windows Mobile 5.0 Pocket PC SDK and click the single left pointing arrow (between the two panes) to remove this selection.

9.       From the Installed SDKs pane on the left, select MyCompact7_SDK (or the SDK associate with the target device you are working with) and click the single right pointing arrow to add to the Selected SDK pane, as shown in Figure 4.

Fig-04

Figure 4

10.   After the MyCompact7_SDK is added, click Next to continue and bring up the Project Settings screen, as shown in Figure 5.

Fig-05

Figure 5

11.   Keep the default selection to create a Windows application project,

12.   Click Finish to complete the final step, and setup the initial project workspace.

At this point the new project wizard generates the initial Compact7NativeApp project workspace, in the following folder: 

C:\Lab.Compact7\Compact7NativeApp

Add Codes to Display Hello World

In this section, we will add some codes to the project to display a simple hello world message.

Continue from the previous exercise, with the newly created Compact7NativeApp project active, work through the following steps to add codes to the project:

1.       From the VS2008 IDE, click on the Solution Explorer tab to bring focus to the Solution Explorer window.

2.       From the Solution Explorer, under the Source Files folder, double click on the Compact7NativeApp.cpp file to open this file for editing in the code editor windows, as shown in Figure 6.

Fig-06

Figure 6

3.       From the code editor window, locate the following block of code:

case WM_PAINT:

    hdc = BeginPaint(hWnd, &ps);

   

    // TODO: Add any drawing code here...

 

    EndPaint(hWnd, &ps);

    break;

4.       Replace the preceding code with the following:

case WM_PAINT:

    RECT rect;

    GetClientRect (hWnd, &rect);

    hdc = BeginPaint(hWnd, &ps);

    //

    DrawText(hdc, TEXT("Hello World from Compact 7 Native application!"), -1,

                        &rect, DT_CENTER|DT_VCENTER|DT_SINGLELINE);  

           

    EndPaint(hWnd, &ps);

    break;

5.       From the VS2008 Build menu, click Build Solution to build the project and generate the executable binary, Compact7NativeApp.exe.

Download Application to Target Device

To download the application to the target device, we need to establish connectivity between the VS2008 IDE and the target device, using Core Connectivity framework (CoreCon).

To establish CoreCon connectivity between the VS2008 IDE and the target device, we need the following:

·         Include the necessary CoreCon files to the OS runtime image.

·         The target device’s IP address.

·         Launch the ConmanClient.exe and CMAccept.exe executable on the target device.

For information about CoreCon connectivity, refer to the following application note:

·         Core Connectivity (CoreCon) for Compact 7 Application Development            

http://bit.ly/MO00ZV

Establish Connectivity to the Target Device

From the VS2008 IDE, with the Compact7NativeApp project active, work through the following steps to establish connectivity to the target device:

1.       From the VS2008 IDE, click on the Device Options icon to bring up the Options screen.

(You can accomplish the same by selecting Tools à Options from the VS2008 menu.)

2.       Select Device Tools\Devices  from the left pane.

3.       On the right, select the SDK associated with the target device.  For this exercise, select MyCompact7_SDK.

4.       Click on Properties to bring up the Device Properties screen.

5.       Click on Configure to bring up the Configure TCP/IP Transport screen.

6.       Select the “Use specific IP address” option, enter the target device’s IP address and click OK to continue.

7.       Click OK to close the Device Properties screen and the Option screen.

8.       From the VS2008 IDE, click on the “Connect to Device” icon, to establish connectivity to the Compact 7 target device.

(You can accomplish the same by select Tools à Connect to Device from the VS2008 menu.)

Download Application to the Target Device

With CoreCon connectivity established between the VS2008 IDE and target device, from the VS2008 Debug menu, click on Start Debugging to download the application to the target device.

Note:    Douglas Boling wrote an outstanding book (“Programming Windows Embedded CE 6.0”, published by Microsoft Press), which covers native code application development for Windows Embedded CE 6.0 in great detail.  Although the book is written for CE 6.0, native code development for Compact 7 is similar to CE 6.0.