# Monday, May 14, 2007

Waiting for a Process

There have been numerous occasions where I've needed to write code to launch another process and wait for it to complete, usually taking some action based on the exit code. Therefore I've got a handy helper method to do this. It has changed a few times and is made much simpler in .NETCF v2.0 by taking advantage of the Process class. Most recently I used the code in one of the book chapters to show automatic installation of the Microsoft Message Queue (MSMQ) components onto a Windows Mobile device. The method is named ShellWait, as the name implies it launches a process and waits, the return value is the exit code from the process. If the application doesn't exist it returns -1 immediately.

[C#]

//helper function to launch a process and wait for the result code
private static int ShellWait(string app, string args)
{
   if (!File.Exists(app))
   {
      return -1;
   }


   Process p = Process.Start(app, args);
   p.WaitForExit();


   return p.ExitCode;
}

 

[VB]

Private Shared Function ShellWait(ByVal app As String, ByVal args As String) As Integer
   If Not File.Exists(app) Then
      Return -1
   End If

   Dim p As Process = Process.Start(app, args)
   p.WaitForExit()

   Return p.ExitCode
End Function

#    Comments [0] |
# Friday, May 04, 2007

Fabien Decret is now blogging

Fabien is a French mobile developer who regularly posts answers to the Compact Framework newsgroup. He has started blogging and already posted on a number of Windows Mobile and Visual Studio topics in both French and English. You can view Fabien's blog here:-

http://fabdecret.blogspot.com/

#    Comments [0] |
# Tuesday, May 01, 2007

New Sounds sample in Windows Mobile 6 SDK Refresh

The Windows Mobile 6 SDK Refresh is available today. It includes some documentation enhancements and new samples. One of these is called RingtoneManager and is a C# application which wraps all the Sound APIs for ringtone management and sound playback, the latter of which were introduced with Windows Mobile 6. This is great because it gives you all the P/Invokes etc you need to use this functionality yourself. However expect to see these Windows Mobile specific APIs in the next version of Mobile In The Hand.

#    Comments [0] |
# Friday, April 27, 2007

Book done, MEDC next!

We've finished all the writing for the book, and it's now winging it's way to the printers. This week I finished converting all my sample code to Visual Basic so that we'll have two versions of all the sample code in the book. I have to thank all of the people behind the book, the team at MS Press and my fellow authors for making my first writing experience such a pleasant one. I'm eagerly looking forward to seeing the finished book later in May. Just when I thought it was safe to kick back and relax I'll be off to Las Vegas for MEDC 2007 on Monday.

This years event promises to be a great one - lots of content on Visual Studio Orcas, .NETCF 3.5 and a refreshed version of the Windows Mobile 6 SDKs. I'll be taking part in one of the panel discussion session, along with my fellow authors, members of the .NET Compact Framework team and OpenNETCF. The session is on both Wednesday and Thursday so you should find one to fit your schedule.

I look forward to seeing you in Las Vegas!

#    Comments [3] |
# Tuesday, April 03, 2007

Deprecated APIs in Windows Mobile 6

Over on the Windows Mobile Developer Wiki is a topic listing all the APIs and technologies which are deprecated in Windows Mobile 6. This is essential reading for any Windows Mobile developer:

http://channel9.msdn.com/wiki/default.aspx/MobileDeveloper.DeprecatedFeaturesInWindowsMobile6

#    Comments [0] |
# Friday, March 30, 2007

Determine Version of Connected Device

When your device is synchronised with ActiveSync (or Windows Mobile Device Center in Windows Vista) a number of device properties are written to the registry. This allows you to gather information on the device during a custom installation or from a desktop application. One of these properties is the version number of the device, the exact key is:-

HKEY_CURRENT_USER\Software\Microsoft\Windows CE Services

The version is stored in a DWORD value called "DeviceVersion", its contents look like this:-

0x1560105

As raw bytes it would be {0x5, 0x1, 0x56, 0x1 }. The first byte represents the major version number, the second is the minor version and the last two bytes together are the build number e.g. 0x156 = 342. Putting that all together shows that my connected device is returning version:

5.1.342

Which is exactly what I can see on the Settings > System > About screen for the device (which is a Pocket PC running Windows Mobile 5.0 AKU 3.0).

#    Comments [0] |
# Monday, March 26, 2007

TomTom In The Hand 6.1

I've been a bit quiet over the past few weeks, on vacation and at the Microsoft MVP Summit. I've also been working on the TomTom In The Hand library and today have released a new version.

It turns out that TomTom SDK 6 shipped with a known bug that prevents you from passing negative co-ordinates into any of the methods (returned values were okay). At the moment I believe that our library is the only one which has a fix for this bug which was a major headache for developers. You can now use TomTom through this library wherever you reside in the world (assuming you have map coverage of course) without making any changes to your existing code.

This release also adds some new functionality - The RawGpsReceived event on the Navigator object allows you to receive NMEA data from TomTom which allows you to share this data if you are not already using a multiplexer such as the Windows Mobile 5.0 GPS service or Franson GPS Gate or similar.

#    Comments [0] |
# Friday, March 09, 2007

Personal Area Networking in the Delphi Magazine

John Penman has written an article in the March edition of Delphi Magazine entitled "Simple Wireless Networking with Delphi for .NET" which describes using the 32feet.NET library from Delphi code. It walks the user through each of the areas of functionality in the library: IrDA, Bluetooth and Object Exchange. Its written for the v1.6 version, but the object model in the latest v2.1 version is a superset so the code will work with the latest version.

#    Comments [0] |
# Thursday, March 01, 2007

What's New For Managed Developers In Windows Mobile 6 (Part 3)

Thankfully after the previous false-start the Windows Mobile 6 SDKs are now back online and here to stay.

In the last post, I looked at new properties in the Microsoft.WindowsMobile.Status namespace. It turns out that there are some minor improvements in the Microsoft.WindowsMobile.Forms namespace too. The ChooseContactDialog gets a few new properties:-

  • FilterRequiredProperties - When true only contacts with the properties specified for RequiredProperties will be shown. This was default behaviour in Windows Mobile 5.0
  • EnableGlobalAddressListLookup - When true allows the user to also search the GAL (if available)
  • IncrementalFilter - Contains the text of the filter box at the top of the dialog.
  • NoUI - No UI is shown at all (Not sure exactly why you'd want to do this...).
  • NoUIOnSingleOrNoMatch - If only a single outcome is possible the ShowDialog method returns immediately without prompting the user.
#    Comments [0] |
# Monday, February 26, 2007

Programmatically Activating Speakerphone

Windows Mobile devices, both Smartphone and Pocket PC support Speakerphone functionality. When operating through the Phone application the end user can toggle the state, up until now there has been no documented way to achieve this through code. Last year I investigated the issue on behalf of one of my readers and failed on several attempts at simulating a press-and-hold of the green phone button. It turns out that the device issues a specific key constant to change the state, and this can be simulated through code. It also turns out that the constant is equivalent to VK_F16 (thats Keys.F16 for managed code). I've wrapped up the necessary P/Invoke into the following code:-

public sealed class SpeakerPhone
{
private SpeakerPhone() { }

/// <summary>
/// Toggles the SpeakerPhone state.
/// </summary>
public static void Toggle()
{
//keydown
NativeMethods.keybd_event((byte)Keys.F16, 0, 0, 0);
//keyup
NativeMethods.keybd_event((byte)Keys.F16, 0, NativeMethods.KEYEVENTF_KEYUP, 0);
}

internal static class NativeMethods
{
internal const int KEYEVENTF_KEYUP = 0x0002;


[System.Runtime.InteropServices.DllImport("coredll.dll")]
internal static extern void keybd_event(byte bVk, byte bScan, int dwFlags, int dwExtraInfo);
}
}

 

Since this just toggles the state, you can't determine the current state at any particular time. This code has been tested on Windows Mobile 5.0 and beyond (It possibly works on Windows Mobile 2003 but I haven't tested), it doesn't work on the Windows Mobile 5.0 Emulators as Speakerphone isn't implemented. I was able to establish a call on speakerphone using the following code:

Microsoft.WindowsMobile.Telephony.Phone p = new Microsoft.WindowsMobile.Telephony.Phone();
p.Talk("01234567890");
SpeakerPhone.Toggle();

Once the call is ended the speakerphone state is restored on subsequent calls.

#    Comments [0] |
# Wednesday, February 21, 2007

Richard Jones is Blogging

Richard has just started blogging, starting with a sample for maximising screen space by creating a Vista style textbox with integral label, and a description of what he has been up to in the fight against "Monkey Code". I've subscribed to his RSS feed and added him to the blogroll.

#    Comments [0] |
# Saturday, February 17, 2007

Emulator Images in the Windows Mobile 6 SDKs

The Windows Mobile 5.0 SDKs shipped with a number of emulator images, and additional form factors were made available in separate packages at a later date when they were introduced with AKU2. Below is the list of emulator images which will ship with the Windows Mobile 6 SDK:-

Windows Mobile 6 Standard

  • Windows Mobile 6 Standard (176x220)
  • Windows Mobile 6 Standard Landscape QVGA (320x240)
  • Windows Mobile 6 Standard QVGA (240x320)

Windows Mobile 6 Professional

  • Windows Mobile 6 Classic (No Phone) (240x320)
  • Windows Mobile 6 Professional (240x320)
  • Windows Mobile 6 Professional Square (240x240)
  • Windows Mobile 6 Professional Square QVGA (320x320)
  • Windows Mobile 6 Professional Square VGA (480x480)
  • Windows Mobile 6 Professional VGA (480x640)

Except for the square form-factors all of the Professional emulator images support screen rotation, the emulator rotates the device skin in place so that the screen is always shown in the correct orientation on the development computer.

#    Comments [0] |
# Thursday, February 15, 2007

Windows Mobile 6 SDKs Update

Turns out the SDKs haven't been abducted by aliens, James Pratt reveals the story here on the Windows Mobile blog. So if you missed them you'll have to wait until 1st March for their official release.

The good news is that there will be an update to the SDKs due out on May 1st with new emulator images, additional samples and documentation improvements. Lets hope that all my bug reports submitted on documentation errors in the current release are resolved in that release.

#    Comments [0] |
# Wednesday, February 14, 2007

What's New For Managed Developers In Windows Mobile 6 (Part 2)

When I previously posted the list of additional system properties I was using the Windows Mobile 6 SDK Documentation as a reference. Well it turns out that there are even more new properties, you can view them using Object Browser in your project but they aren't included in the documentation. The other new properties are:-

  • CameraEnabled - This in addition to existing CameraPresent property
  • CellularSystemAvailable1xrtt
  • CellularSystemAvailableEdge
  • CellularSystemAvailableEvdo
  • CellularSystemAvailableEvdv
  • CellularSystemAvailableGprs
  • CellularSystemAvailableHsdpa
  • CellularSystemAvailableUmts
  • CellularSystemConnected1xrtt
  • CellularSystemConnectedEdge
  • CellularSystemConnectedEvdo
  • CellularSystemConnectedEvdv
  • CellularSystemConnectedGprs
  • CellularSystemConnectedHsdpa
  • CellularSystemConnectedUmts
  • ClamshellClosed
  • DeviceLocked
  • KeyLocked
  • LockStates - A combination of flags for Device, Key and Sim locks
  • SimLocked
  • PhoneTalkingCallStartTime

 

#    Comments [0] |