| By Amit Chopra | Article Rating: |
|
| December 20, 2006 08:30 PM EST | Reads: |
24,010 |
Connecting to the Internet Using the Emulator
The
Emulator can also be used to connect to the Internet or any other
server on your network. If you have cradled the emulator using
ActiveSync, there is really nothing special that is needed to be done.
Once ActiveSync is in the "Connected" state you should have Internet
connectivity from the Device Emulator. If you are on a corporate
network and access external Web sites via a proxy server you will be
prompted to set it up as you would on a real device. The settings used
here are similar to the ones that you would use to set up your desktop
IE (Tools -> Internet Options -> Connections -> LAN settings).
You can then connect to local intranet and Internet sites using the
emulator.
However, if you wish you connect via TCP and do not want to use ActiveSync, you need to download the Virtual machine Networking driver and follow the steps below. The Virtual Machine Networking Driver can be downloaded from www.microsoft.com/downloads/details.aspx?familyid= DC8332D6-565F-4A57-BE8C-1D4718D3AF65&displaylang=en.
Once this driver is installed, change the default transport of the emulator from DMA to TCP/IP, and give your emulator and IP Address. This can be done in Visual Studio 2005: click Tools | Options | Device Tools | Devices.
The emulator usually uses DHCP connectivity to get its own IP address, but if you use static IP addresses, give the emulator an IP address that is valid for your network.
From the configuration properties of the emulator select the Network tab and select the Enable NE2000 PCMCIA network adapter and bind to box. In the drop-down list, select the Connected network card, which represents the network card on the host computer. Close the dialog boxes.
Then from the emulator image, Click Start | Settings | Connections tab | Connections | Advanced tab | Select Networks to configure the Pocket PC Connection Settings. Be sure My ISP is selected under both drop-down lists.
You can get more details on this scenario on our Team Blog at http://blogs.msdn.com/vsdteam/default.aspx.
Testing an Application that Behaves Differently When Cradled
This is my favorite scenario; I find the new device emulator extremely
useful. In this scenario I have an application that has to behave
differently when connected to the PC (Cradled with Active Sync) from
when it's not. This is very typical of any real life Line of Business
Application, and the Device Emulator can even help you test
applications of this nature.
In my case, I also depend a lot on the new Managed APIs for State Notification - which ship as part of the Windows Mobile 5.0 - to reduce the amount of code I need to write to check if my application is running cradled or not. The new Managed APIs in Windows Mobile 5.0 make it very simple not only to detect the current state, but also to notify your application when it changes.
In my Visual Studio 2005 project (targeted for a Windows Mobile 5.0 Pocket PC application), I add reference to the following assemblies:
Microsoft.WindowsMobile
Microsoft.WindowsMobile.Status
Then, in my Form Class, I create an instance of a SystemState Property called SystemState.Cradle-Present:
public SystemState S = new SystemState(SystemProperty.CradlePresent);
When my application starts, I hook it up to listen to the notifications fired when this property changes. This notification will be fired when your device is cradled to your machine and when it is un-cradled:
S.Changed += new ChangeEventHandler(S_Changed); //add handler
Then, I create a simple event handler that will handle the change of this property. The code would look something like this:
void S_Changed(object sender, ChangeEventArgs args)
{ if (Convert.ToInt16(args.NewValue) == 1)
{ //Your code to handle connected state
Label1.Text = "Connected"; }
else
{ //Your code to handle disconnected state
label1.Text = "NOT Connected"; }
}
Once I have defined the different behaviors in my application, I don't need a device to test the scenario. This is where the Active Sync Partnership feature comes in handy.
You can deploy the application to the emulator as normal. One the application is running, you can bring the Device Emulator manager and select cradle with your emulator image. You will notice that as soon as the partnership is established, the notification will be sent to your app and the event handler for that will be called. In my case I will see the Label1.Text change to connected. Then you can Right Click again using the Device Emulator Manager and select UnCradle and you will see that the event is fired again and now the label will change to NOT connected.
This was an over-simplified scenario, but it really highlights how powerful the combination of the new Windows Mobile Managed API and Device Emulator can be for you as a Windows Mobile Developer.
Saving State of the Images
When you install Visual
Studio 2005, and launch and emulator image, you will notice how quickly
the image loads up. This is because of a feature called "Saved State."
As a developer, you can create your own saved states for these images.
For example, if you want the image to always have a certain program on
it or some specific settings, you can install / set it when the
emulator is running and then select Save State and Exit from the File
Menu. This way, when you bring up the emulator next time, you will find
that your settings are all preserved.
The way I use this feature for everyday productivity is by pre-installing .NET CF 2.0 on my images to speed up the deploy time of my applications. The Windows Mobile Emulator images don't have .NET CF 2.0 installed (since Windows Mobile 5.0 ships with .NET CF 1.0 Sp3 in ROM), but most of the applications I use are based on .NET CF 2.0. So instead of waiting every time for Visual Studio to deploy .NET CF 2.0 to my emulator, I install it once and then save the image. Now, every time that image loads, it already has .NET CF 2.0 on it, which saves me a lot of time deploying and debugging my applications.
To launch a Saved State image from the command line, just use the following and pass on the name of .dess image:
DeviceEmulator.exe /s ImageName.dess
While the Device Emulator does not have the ability to save and load multiple Saved States, here is a technique I find useful.
In the Tools->Options->Device Tools->Device, I select a basic image, for example, Windows Mobile 5.0 Pocket PC Emulator, as shown in Figure 5.
Then, do a Save As and save that image under a different name.
Now, when deploying the application, you will notice a new emulator available in the Deploy to Device Dialog.
You can then deploy your application to it, alter the setting, etc., and those will be available to you on your machine. As you can see from the dialog, I have an Image Called "Windows Mobile 5.0 Pocket PC Emulator with .NET," which I created the same way, and .NETCF 2.0 is pre-installed on that image. If you are wondering where the My Computer came from, you can read find out on this blog: http://www.danielmoth.com/Blog/2005/01/deploy-to-my-computer.html.
Starting the Emulator in a Preconfigured Manner
There are times when you wish that as soon as you start the emulator,
it has already been configured in a specific manner. This feature is
referred to as "XML provisioning," and it allows you to pre-configure
your emulator to add Internet Explorer favorites, have the correct
Internet Explorer proxy server set up, add registry keys, set time
zones and locales, etc.
Let's say you wish to pre-configure Internet Explorer in Pocket IE to have a shortcut to your favorite link, such as .NET Developer's Journal (http://dotnet.sys-con.com/). First, you would create an XML Provisioning File, say, with the name myIEFavorite.xml like this:
<wap-provisioningdoc>
<characteristic type='BrowserFavorite'>
<characteristic type='MSDN Mobility'>
<parm name='URL' value='http://dotnet.sys-con.com'/>
</characteristic>
</characteristic>
</wap-provisioningdoc>
Now, from Inside Visual Studio 2005, click Tools | Options | Device Tools | Devices, and in the Options dialog box, under Devices, select the Windows Mobile 5.0 Pocket PC Emulator. Click Properties. In the Windows Mobile 5.0 Pocket PC Emulator Properties dialog box, click the Configure button next to Device Emulation Startup Provider, and in this dialog, for Configuring the Emulation Bootstrapper, click the ellipsis button, and then browse to and select the myIEFavorite.xml file.
The next time you connect to this emulator from Visual Studio, Visual Studio will boot strap the emulator with this file, and you will notice that this favorite is added to your existing favorites in Pocket IE.
Do You Want to Write Your Own Emulator?
Believe me
when I tell you that writing emulators can be very hard, but I am
pleased to inform our readers that the source code for the Device
Emulator 1.0 has been released under the academic license. http://blogs.msdn.com/barrybo/archive/2006/07/17/668492.aspx has the details of this project.
You can download the entire project for Device Emulator 1.0, which you can compile in Visual Studio 2005 to build your own emulator. It's great for experimenting and learning how emulators are built.
What's Next?
The device emulator continues to
enhance performance as well as add support for emulation of additional
device peripherals. For example, The Device Emulator V2.0 (CTP), when
used with images rolled by Windows Embedded 6.0, will be able to
emulate even the batter setting for the device.
Using the emulator, you will be able to alter the battery strength, and test your application's behavior in different battery configurations. (This feature does not work with the existing Windows Mobile 5.0 images but will be supported in images of the future releases of Windows Mobile OS).
Having the ability to change the battery on-the-fly can save developers hours of precious time of waiting for their battery to drain on their real device, while trying to test how their application works in a low battery scenario.
Currently, all the configuration for the emulator is changed via the configuration dialog, however, in future releases, the emulator will support these changes via automation, and hence, you can write an application to change the setting on-the-fly on a running instance of the emulator without having to go to the configuration dialog.
To stay in touch with what's happening in the device development space and emulation technologies, subscribe to the RSS Feed for our team blog and use the forum (http://forums.microsoft.com/msdn/showforum.aspx?forumid=76) to discuss issues with us. You can also learn about the device emulator first hand from the blog of the Architect Barry Bond (http://blogs.msdn.com/barrybo/), who created the Microsoft Device Emulator.
Published December 20, 2006 Reads 24,010
Copyright © 2006 SYS-CON Media, Inc. — All Rights Reserved.
Syndicated stories and blog feeds, all rights reserved by the author.
More Stories By Amit Chopra
Amit Chopra is the release program manager for the Visual Studio for
Devices team. He also manages the sustained engineering efforts for
eMbedded Visual C++ 4.0 and Visual Studio 2003. He can be contacted at achopra@microsoft.com.
- Kindle 2 vs Nook
- Confessions of a Ulitzer Addict
- IBM Hardware Chief, Intel VC Exec Arrested in Insider Trading Scam
- Tactical Cloud Computing Panel at 1st Annual GovIT Expo
- Ulitzer.com Named Exclusive "New Media" Sponsor of Cloud Computing Conference & Expo
- Infrastructure-as-a-Service Will Mature in 2010: Microsoft's David Chou
- Windows 7 – Microsoft’s First Step to the Cloud
- Cloud Expo and the End of Tech Recession
- Jill Tummler Singer, Deputy CIO of CIA, Keynotes at GovIT Expo
- Reality Check at the Cloud Computing Expo
- Visual Studio 2010 Is Cloud Friendly
- Fired SCO CEO Fires Back
- Kindle 2 vs Nook
- The Difference Between Web Hosting and Cloud Computing
- Ajax in RichFaces 3.3, JSF 2 and RichFaces 4
- Confessions of a Ulitzer Addict
- Wave on Ulitzer: Confessions of a Google Wave Fanboy
- IBM Hardware Chief, Intel VC Exec Arrested in Insider Trading Scam
- Cloud Computing Best Practices
- Tactical Cloud Computing Panel at 1st Annual GovIT Expo
- Ulitzer.com Named Exclusive "New Media" Sponsor of Cloud Computing Conference & Expo
- Infrastructure-as-a-Service Will Mature in 2010: Microsoft's David Chou
- Eval JavaScript in a Global Context
- Windows 7 – Microsoft’s First Step to the Cloud
- Google Maps and ASP.NET
- Crystal Reports XI & How It Has Changed
- Converting VB6 to VB.NET, Part I
- Creating Controls for.NET Compact Framework in Visual Studio 2005
- Where Are RIA Technologies Headed in 2008?
- How to Write High-Performance C# Code
- AJAX World RIA Conference & Expo Kicks Off in New York City
- Implementing Tab Navigation with ASP.NET 2.0
- i-Technology Photo Exclusive: Bill Gates & Steve Jobs In "Nerds"
- .NET Archives: Getting Reacquainted with the Father of C#
- i-Technology Viewpoint: "SOA Sucks"
- Programmatically Posting Data to ASP .NET Web Applications
























