by July 1, 2005 0 comments



Application development is not just about getting confined to desktop and/or server based development. With devices like smart phones and PocketPCs hitting the market and entering at the price level of other cellphones, but with much richer functionality, make them a better value for money. Not only do they offer all conventional cellphone features but also go beyond that with applications such as Pocket Word, Pocket Excel, MSN Messenger and lots more being developed by organizations all over the globe to do a variety of tasks (including finance management). And all these
applications run on a version of Windows customized for the capability and form factor of these devices-called Windows CE. 

In this article(code for this is uploaded on forums.pcquest.com in the ‘Developer Stuff’, we shall see what goes into developing applications for such devices and what are the tools involved to do so.

Difference between PocketPC and smart phone
Before you set out to develop for PocketPC or smart phone, you should understand the primary differences between the two kinds of devices and their platforms. 

Direct
Hit!

Applies to: .NET Compact Developers, Win Mobile Developers 

USP: Understand how to develop for the SmartPhone 2003 platform and build a simple dialer as an example

Primary Link: http://msdn.microsoft.com/mobility/

Google keywords: smart phone development

At the very base of these two devices is the Windows CE OS. Windows CE can be used for any kind of compact device development-PocketPC and smart phone happen to be just one of them. When Windows CE is customized for these mobile devices, it gets a new name-Windows Mobile. And then, when Windows Mobile is customized for the specific form-factor and hardware, it becomes either the PocketPC platform or the smart phone platform. 

A PocketPC is much bigger a device compared to a smart phone but both run on Windows CE OS. However, the OS is customized for the hardware and form-factor of each of these devices-for
instance, the UI of PocketPC is bigger than that of a smart phone, PocketPC supports touch-screen/stylus-based input, while smart phone doesn’t. Also,
PocketPC has more RAM, additional battery support, while smart phone does not, different CPU processing power and so on. 
The form-factor also defines a lot to the way application will be built-especially from the UI perspective. Also, the OS implementation supports some APIs on PocketPC that are not completely available (and sometimes not available) on the smart phone platform. 

Now that the differences are talked about, let us discuss how to go about developing an application for either of these two platforms.

Developing for smart phone 2003 
There are two kinds of applications that can be written for Windows CE,-and thus, for smart phone and PocketPC platforms- unmanaged (non-.NET) and managed applications. For developing unmanaged applications, one uses embedded VC++. Applications written with this run native to the underlying OS and the experience is very similar to developing applications using the regular VC++ development environment. However, it’s a standalone product, ie, it doesn’t integrate in Visual Studio.NET. So it needs to be downloaded and installed. On the other hand, managed applications written for Windows CE are targeted for what is called the .NET Compact Framework-a mini version of the regular .NET Framework that has been
customized for the PocketPC and smart phone platforms. To develop applications using the .NET 

Start off your development using the Smart Device Project Application in VS.NET 2003 

Compact Framework, you can use Visual Studio.NET 2003 or later-you can use C# or VB.NET to build Smart Device Projects as shown in the adjacent screenshot.

This project type will allow you to build managed applications that target PocketPC 2002, PocketPC Phone Edition based
systems that run on Windows CE 4.1 or later. There’s no out of the box support to build applications for PocketPC 2003 or smart phone 2003 applications unless you download the emulator images and install them on your machine. Once that is done, VS.NET 2003 will support building the applications for these platforms as well, as shown in the screenshot above.

Managed applications written this way still target .NET Compact Framework 1.0. On the other hand, Visual Studio 2005 has built in support for PocketPC 2003 and smart phone 2003 platform
development that still target .NET Compact Framework 1.0 but managed applications built using it target .NET Compact Framework 2.0 (Whidbey) if written for Windows CE 5.0/Windows Mobile 2005. But there’s no support for the older PocketPC 2002.
You can download these SDK/Emulator images from the following link.

http://www.microsoft.com/downloads/details.aspx?familyid=6A34DC83-C3CE-4A4C-AB83-491FD5729551&displaylang=en 

Building a smart phone 2003 dialer
Here, we shall build a phone dialer application using Visual Studio 2005 for building smart phone 2003 applications. We’ll also use Windows CE OS APIs from managed code, and finally write an
application for the mobile device that does something real-programmatically make phone calls!

To start off, we create a Smart Phone Device Application project that brings up the smart phone skin that we customize by adding a label and textbox that will take the number to be dialed as the input. However, notice the toolbox for smart phone development (screenshot on the right).

Support for PocketPC 2003 and SmartPhone 2003 Platforms once the emulator images have been installed

Screen development for the smart phone is made easy by forms like interface in VS.NET

You will notice that there is no button control. Any command action happens as a consequence of menu option selection-another difference between PocketPC and smart phone development. We add the Dial menu option and our smart phone 2003 application looks as above.

Now that the UI is done, let’s add support to make phone calls. While our UI and application are being built over the .NET Compact Framework, it does not support making phone calls. So in order to that, we need to use Platform Invocation 

Services (PInvoke) and make calls into the 
Windows CE OS and get our work done. The API that we need to invoke is called PhoneMakeCall and is prototyped as:

LONG PhoneMakeCall(
PHONEMAKECALLINFO *ppmci);

SmartPhone 2003 Toolbox in VS 2005 Beta 2

It takes only a single parameter that is a pointer to a structure, called PHONEMAKECALLINFO, which contains the details of the call being made. This structure has the following layout.

typedef struct tagPHONEMAKECALLINFO{
DWORD cbSize;
DWORD dwFlags;
PCWSTR pszDestAddress; 
PCWSTR pszAppName; 
PCWSTR pszCalledParty;
PCWSTR pszComment;
} PHONEMAKECALLINFO, * PHONEMAKECALLINFO;

For PInvoke, the method call definition becomes 

[DllImport("PHONE.Dll")]
internal static extern int PhoneMakeCall(ref PhoneMakeCallInfo ppmci);

It’s implemented out of PHONE.DLL. Thus, the corresponding DllImport attribute. Next, we convert the Win32 representation of the
PHONEMAKECALLINFO structure and it becomes as:

internal struct PhoneMakeCallInfo
{
public int dwSize;
public CEPhoneCallFlag dwFlags;
public IntPtr pszDestAddress;
IntPtr pszAppName;
public IntPtr pszCalledParty;
IntPtr pszComment;
}

Now the only things that remains is to write code that will make the phone call. For this, issue:

public static bool MakePhoneCall(string strPhoneNumber, string strCalledPartyName)
{
// create a byte array to specify the calling details
PhoneMakeCallInfo info = new PhoneMakeCallInfo();

// set the size..
info.dwSize = 24;

// set the flag
info.dwFlags = PhoneCallFlag.Default;

// Set the phone number..
uint iDataBytesCount = ((uint)(strPhoneNumber.Length + 1)) * UnicodeEncoding.CharSize;
byte[] arrData = Encoding.Unicode.GetBytes(strPhoneNumber);
IntPtr ptrPhone = LocalAlloc(64, iDataBytesCount);
Marshal.Copy(arrData, 0, ptrPhone, arrData.Length);
info.pszDestAddress = ptrPhone;
// Set the Called Party
IntPtr ptrCalledParty = IntPtr.Zero;
if (strCalledPartyName != null)
{
iDataBytesCount = ((uint)(strCalledPartyName.Length + 1)) * UnicodeEncoding.CharSize;
arrData = Encoding.Unicode.GetBytes(strCalledPartyName);
ptrCalledParty = LocalAlloc(64, iDataBytesCount);
Marshal.Copy(arrData, 0, ptrCalledParty, arrData.Length);
}

info.pszCalledParty = ptrCalledParty;

return (PhoneMakeCall(ref info) == 0) ? true : false;
}

SmartPhone 2003 Dialer application in execution

We start off by instantiating the PhoneMakeCallInfo structure and set its initial size and call flag-the latter indicates if the OS will prompt us before making the phone call or not and is defined as:

public enum PhoneCallFlag
{
Default = 1,
PromptBeforeCalling = 2
}

Next, since we got the phone number as a System.String, we get its correct unicode length and also convert the string to an array
representation. We then allocate some memory in the OS and copy the array contents, ie, the phone number, to the allocated memory and then store the location’s reference in the
PhoneMakeCallInfo’s pszDestAddress member. If name of the entity being called is also specified, we also copy it to a memory location and set its reference.

Finally, we invoke the PhoneMakeCall API, via PInvoke, and pass-by-reference the instance of PhoneMakeCallInfo structure that contains the details of the phone call to be made. A Boolean value is returned by our method implementation to indicate success or failure, while the OS API returns zero to indicate success. The adjacent screen shows the application on a phone. Now, build the application and with your smart phone 2003 device connected to your machine via ActiveSync, run it. VS automatically deploys the application on your device, with .NET Compact Framework if required, and then your application will execute. Enter a number and press the Dial menu option-the phone will make the call for you.

Kumar Gaurav Khanna, www.wintoolzone.com

No Comments so far

Jump into a conversation

No Comments Yet!

You can be the one to start a conversation.

Your data will be safe!Your e-mail address will not be published. Also other data will not be shared with third person.