# Monday, August 07, 2006

Broadcom Bluetooth Stack SDK Now Free

In an amazing about-face, Broadcom have released their Bluetooth SDK (Both the desktop and Windows CE versions) for free on their website, all you need to do is provide some basic information to register and you'll receive a download link via email. In many ways the Broadcom stack has always been ahead of the Microsoft version in terms of supported profiles, the real stopper has been the need to purchase the SDK to develop for it.

Thanks to forum member Robert83 for the heads-up!

It will be interesting to see how this affects the balance of stacks on new devices, now that both have an accessible programming model, however each stack is not without it's faults - lack of radio control for Broadcom and fewer profiles supported by Microsoft for example.

#    |
# Tuesday, July 18, 2006

Windows Mobile 5.0 Bluetooth Virtual Serial Ports

Among the fairly modest enhancements to the Microsoft Bluetooth stack in Windows Mobile 5.0 is a new unified system for assigning virtual COM ports. Previously this was only exposed to the user via OEM provided plugins. Very often you were limited to a single incoming and outgoing port. The Pairing process on Windows Mobile 5.0 now does a service discovery and allows the user to choose which services they wish to use, when "Serial Port" is ticked in the list you can then use the new interface on the "COM Ports" tab to create a virtual COM port for the device.

All of the settings are stored in the registry so that you can also programmatically query what ports are setup and to which devices they map. The magic happens at:

HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Bluetooth\Serial\Ports

This key contains a multi-string value containing all of the available COM ports on the system. This should have been setup by the OEM so that it does not contain reserved COM port identifiers. For example on my iMate K-Jam this value contains:-

COM6

COM7

Below this key there will be a key for each device setup with a virtual COM port, the key will be named with an 8 byte hexadecimal device id (16 characters). This contains values with settings for the port such as Encryption etc. The most useful is "Port", a string value containing the COM port name e.g. "COM6". Each device can have only one virtual COM port assigned, so if you run through the "New Outgoing Port" sequence for the same device it will overwrite your previous settings. The pairing information for the device is stored in a similarly named key under:-

HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Bluetooth\Device

You can query the values under the device key (again 16 chars for the device id) to retrieve the device name and class of device. When you retrieve paired devices with 32feet.net using BluetoothClient.DiscoverDevices it reads this information for you into a BluetoothDeviceInfo instance.

This new mechanism means that rather than using the awkward RegisterDevice method for registering a virtual COM port (InTheHand.IO.Ports.BluetoothSerialPort in 32feet.net) you can configure the settings through the registry in such a way that they are visible to device user and don't conflict with other ports.

 

#    |
# Friday, June 16, 2006

Bluetooth Experience Icon Program

The Bluetooth SIG have introduced a new branding initiative to help clarify what functionality a Bluetooth device supports using a number of simple icons for popular applications of Bluetooth. The current 5 icons are:-

  • Print (Hard Copy Replacement Profile, Basic Print Profile)
  • Input (Human Input Device Profile)
  • Headset (Headset Profile, Handsfree Profile)
  • Transfer (Object Push Profile, OBEX FTP)
  • Music (Advanced Audio Distribution Profile, Audio Video Remote Control Profile)

Each has specific requirements which must be met for the product to display the icon. It should help to make it possible to identify what functionality a device provides. Windows Mobile 5.0 currently supports the requirements of the Input, Headset and Music icons. It doesn't qualify for Transfer since OBEX FTP is not supported, it is a Windows CE component which is not included in the Windows Mobile platform. And as we know Windows Mobile has no printing support out of the box, however if you have a Bluetooth printer which supports Object Push you can beam Contacts, Appointments and Text/HTML documents to your printer.

#    |
# Tuesday, June 06, 2006

Disable the Touch Screen

If you really need to disable the touch screen on a device, there is a method available, but you'll need to soft-reset the device to restore the functionality. You can call the TouchPanelDisable API, it's not documented in the Windows Mobile SDKs but you'll find it in the CE documentation, declaration is very simple:-

<System.Runtime.InteropServices.DllImport("touch")> _
Private Shared Sub TouchPanelDisable()
End Sub

 

or

[DllImport("touch")]

private static extern void TouchPanelDisable();

There is a possibility that the dll in which this function appears may be different on some devices, so you'll need to do some experimentation first.


#    |
# Thursday, June 01, 2006

SQL Mobile Access Sync Coming Soon

For a while the migration path from Pocket Access to SQL CE / SQL Mobile has been missing a key piece of functionality which many Pocket Access applications relied on - the Synchronisation functionality in ActiveSync which synchronised with an Access database on the PC.

Today we have some good news from the SQL Mobile Team - A tool called here "Sync with Access", which is due out in Beta form in August, will return this functionality for SQL Mobile (and the forthcoming SQL Everywhere Edition).

#    |
# Wednesday, May 31, 2006

Unlock Orange SPV C600 AKU 2.0 For Development

When Orange released their AKU 2.0 ROM for the C600 it introduced a much tighter security policy. A previous loophole for changing security policies involving a signed registry editing application was closed by black-listing the app. Also the online unlocking page from the Orange Developer program doesn't recognise a C600 IMEI. Luckily there is a process in place to get your device unlocked for development and testing. Here are the steps to take, you'll get up and running in a day or two:-

Send an email to developers [at] orange [dot] com

Make sure you include all the following information:-

  • IMEI of the phone exactly as displayed when you dial *#06# (17 digits long)
  • Your full name
  • Your orange network country
  • Phone number for the handset (must be an orange number)
  • Full model number of the device

Using this information they prepare a special unlocking app specific to your device, you should get this back within a couple of days. They will send you this as a zip file with an executable which will run on your desktop and install the component to your device over ActiveSync. On your Smartphone you can then run the tool from Start > Accessories > Security Levels. You can then change the security model to Disabled, Low or High at any time. Turn the phone off and on again for the change to take full effect.

#    |
# Sunday, May 28, 2006

Stop Broadcom Stack Displaying Browser

One of the features of the Broadcom stack is that when you attempt to connect to a virtual COM port it will show the user the Bluetooth Manager and ask them to select a paired device to connect to. You can suppress this and have it always connect to the last used device. You'll need to write to the registry key:-

HKLM/Software/Widcomm/BTConfig/AutoConnect/0008

Create a DWORD value named BTBrowserEnabled and set the value to 0. If you want to re-enable this feature you can reset the value to 1.

#    |
# Sunday, May 21, 2006

Take a Shortcut

There are a number of ways you can make use of Shortcuts within your project. You may create a shortcut to your application during your CAB file installation - either on the Start Menu or perhaps in the \Windows\Startup folder. VS2005 makes this easy because it has a nice file system graphical editor for CAB projects. Another way you can use shortcuts is within your code itself. There are two API functions to support this - SHCreateShortcut and SHGetShortcutTarget. By P/Invoking these from your .NETCF application you can create your own launcher applications which reuse the shortcuts setup for your Start Menu for example.

There are some caveats when using these functions though which you need to be aware of, the documentation has been revised since the Pocket PC 2003 SDK to warn you of this. To understand why let's have a quick look at the contents of an LNK file:-

34#"\My Documents\Templates\Memo.psw"

 

As you can see it's a very simple text format. The number indicates the length of the path, this is followed by the # symbol then the full path to the target. When the path contains a space it must be wrapped in quotes. So what were those caveats? Well whatever path you pass to SHCreateShortcut it doesn't add these quotes how you would expect - you end up with:-

34#"\My" Documents\Templates\Memo.psw

 

This path is invalid and the shortcut won't work. The solution is to wrap any path you pass into SHCreateShortcut with quotes to begin with. Even if the path doesn't contain spaces this will give you a valid shortcut.

The second caveat comes with the SHGetShortcutTarget API. When this reads the shortcut file it doesn't strip out the quotes if present, this means your returned path cannot be used as-is with any of the System.IO functionality. The solution to this one is very simple - perform a Trim() on the returned string passing in the " character - this will remove the leading and trailing quotes and leave you with a valid path. If your shortcuts are to executables and also have arguments specified you will need to split the quoted path from any following arguments.

To demonstrate both of these techniques I've attached a sample VB.NET project. It can create and list shortcuts and when you tap on an item it will launch the target document. For a true launcher application there are some additional steps, for example retrieving the Icon for the file, these are not included in this sample.

Shortcuts.zip (7.27 KB)
#    |
# Tuesday, May 09, 2006

32feet.NET v2.0 Beta 1 Available

I've posted a Beta build of 32feet.NET to the Files section of the site. Please read the file description for a high-level list of changes. This release is the first to be built against .NET v2.0 and will resolve issues encountered with using the v1.x library from a .NET v2.0 VB project. It also consolidates the previously separate dlls into a single dll (InTheHand.Net.Personal.dll) which reduces the overall footprint to 83kb for Infrared, Bluetooth, Object Exchange and Forms functionality. If you are at MEDC and would like to see this version in action, Nick Landry will be using it as part of his session on Thursday at 11:15 "APP335 Tablet PCs and Smartphones: Working Hand-in-Hand to Enable Your Mobile Workforce".

#    |
# Monday, May 08, 2006

Here in Las Vegas for MEDC2006

I'm partly blogging to show I haven't fallen off the face of the earth (yesterday was a near miss though), and partly to plug MEDC2006 which is starting today in Las Vegas.

Being somewhat of a cheapskate I opted for an indirect flight here, the first leg, a mere 8 hours or so from London to Minneapolis went almost without a hitch (in fact we were early), it was all downhill from there. The second flight loaded up and taxied out towards the runway. We then had a message from the captain to tell us that his pre-flight checks indicated that the plane had no hydraulic fluid at all, which could be a bit of a bugger for steering the plane. Thankfully he decided that it would be a bad idea to try. So we then taxied back to the terminal and piled off the plane. Luckily there was another plane available, although because it was a subtly different flavour of 757 they had to reassign many of the seats. So that makes it my 16th plane in the last 2 months, I think after Vegas I'll have a bit of a break from air travel for a while!

So now although still tired I'm ready and looking forward to the cool stuff this week has to offer. I'll be helping out on the MVP Cabana on Wednesday and Thursday, and hanging out with fellow MVPs and OpenNETCF folk.

#    |
# Monday, February 27, 2006

Bluetooth Profiles

This is a post I've been meaning to do for a couple of years and just never got around to it. The table below is an attempt to document the Bluetooth profiles supported on various flavours of Windows. Because Windows CE is modular don't expect every CE device to support all the possible profiles, this table gives an indication of what the platform creators had available to them. In order to conserve space I've made copious use of acronyms (and initialisations), the current release versions of all of these profiles are documented on the public Bluetooth website.

XP SP2 Vista CE.NET 4.2 WM 2003 WM 2003 SE CE 5.0 WM 5.0 WM 5.0 AKU1 WM 5.0 AKU2
A2DP                 Y
AVRCP                 Y
HFP   ?  o o o/Y Y Y Yp Y
HSP   ?  Y o o/Y Y Y Yp Y
HID Y Y Y     Y Y Y Y
FTP     Y     Y      
PAN Y Y     Y      
LAP     Y     Y      
BPP                  
HCRP Y Y              
DUN Yc Yc Y Ys Ys Y Ys Ys Ys
OPP Y Y Y Y Y Y Y Y Y
SPP Y Y Y Y Y Y Y Y Y
c = Client support, s = Server support, o = OEM implemented, p = adds phonebook support, ? Vista recognises these profiles but they don't seem to be used.

What I haven't attempted to do is compare the profiles available on 3rd Party stacks, that would be a little more complex :-)

#    |
# Thursday, February 23, 2006

Writing Provisioning XML for Windows Mobile

This recent article discussed one of the ways you can use XML provisioning data - through a cab file installation. You can also pass the XML to DMProcessConfigXML or ConfigurationManager.ProcessConfiguration in the managed world. But how about creating the XML?

Well you could use notepad and code it all by hand as a worst-case-scenario. The next best thing is to use the XML support in Visual Studio which will at least help to ensure you write valid XML. Mobile In The Hand 2.0 takes this one step further by adding a schema into VS2005 to ensure your document conforms to the msprov schema:-

1. Create a new XML document in your project

2. With the document selected locate "Schemas" in the properties pane.

3. Click "..." to bring up a list of installed schemas

4. Select msprov from the list

5. Start writing your document and watch the intellisense kick in

#    |
# Friday, February 17, 2006

Contact.WebPage

The Managed APIs in Windows Mobile 5.0 expose the Contact.WebPage as a Uri. The problem with this approach is that the user forms are free text and you can enter anything into this field. Probably 9 times out of 10 you'll enter an address such as

www.peterfoot.net

And because the managed API passes this to the Uri constructor and it has no http:// prefix it fails and returns null. However there is a solution to workaround the issue. You can access the Properties collection and access the property and it will be returned as a string. So for example you would use:-

[C#]
string webPage = session.Contacts.Items[0].Properties[Microsoft.WindowsMobile.PocketOutlook.ContactProperty.WebPage];

[VB]

Dim webPage As String = session.Contacts.Items(0).Properties(Microsoft.WindowsMobile.PocketOutlook.ContactProperty.WebPage)

If you then want to use a Uri with this value, check to see if it includes the http:// prefix and if not add your own e.g.

Uri contactsWebpage = new Uri("http://" + webPage);

 

#    |
# Monday, February 13, 2006

OpenNETCF.Windows.Forms.Control2 in SDF 2.0

In SDF v1 I wrote a class called ControlEx which would allow you to host a native windows control within a managed Control. This was the subject of an MSDN article (of which much of the concept applies here too). The implementation was rather convoluted to work around the limits of .NETCF v1.0, and the control was constructed with a Control, which hosted a MessageWindow with some of it's style bits altered which in turn hosted the native control. Luckily hosting controls is easier in NETCF v2.0 but unlike the desktop this functionality is still not built into the base Control class. Which is where Control2 enters the stage.

Like several other classes throughout the SDF the name has been changed to use the 2 suffix, but there are a few other changes I want to draw your attention to. First the inevitable disclaimer, what I'm going to describe won't work with the current Beta release, as I was building the sample code for this post I realised there were a few "nice" features lacking to add a bit more reusable functionality into the Control2 class itself. So lets proceed with how the architecture has changed, and then work through specifics with a sample.

The fundamental feature in .NETCF v2.0 which enables the new architecture is the ability to marshal a managed function as a function pointer to native code. Using this we are able to handle our wndproc in a managed method, this removes the need for the MessageWindow class. Control2 is derived from Control and when added to a form it hooks up a method to process its own windows messages. These are passed to a virtual WndProc method which can be overridden in a derived control to handle specific messages. After this is hooked up the CreateControl method is called, this takes the window class details returned from CreateParams and creates the window as a child of our Control2. This means than in it's simplest form you only need to override CreateParams with a valid class name to host your control.

However Control2 provides only basic functionality to interact with this class - for example automatically resizing when you resize the managed control, and getting/setting the control text. Beyond this you have two ways to interact with the control - add your own properties and methods to your Control2 derived class and from these send windows messages to the native control, and secondly add your own handlers for incoming messages from the control to create events.

For a basic example I've wrapped the CAPEDIT control which is part of WindowsMobile - this is simply a textbox which can Automatically Capitalize The First Letter Of Every Word. Because CAPEDIT is a common control it requires a call to InitCommonControlsEx - there is a static helper method in Control2 to help with this:-

Shared Sub New()

   Control2.InitCommonControls(&H2000)

End Sub

By the way as you've probably noticed, this and the rest of the example are in VB.NET, I would hope that it is self-explanitory enough for you to apply to C# as required.

Interestingly we don't need to worry about the constructor for the control at all, as we don't do anything special. Where the magic happens is in our override for the CreateParams property:-

Protected Overrides ReadOnly Property CreateParams() As OpenNETCF.Windows.Forms.CreateParams

   Get

      Dim cp As CreateParams = MyBase.CreateParams

      cp.ClassName = "CAPEDIT"

      Return cp

   End Get

End Property

And that's it, all we did was change the ClassName in this case. The other parameters such as size are already set for you based on the current size of your managed control.

So as I alluded to earlier, the example is a very simple class so there aren't any events to show you, just a couple of properties which are implemented like so:-

Private allcaps As Boolean = False

Public Property UpCaseAllWords() As Boolean

   Get

      Return allcaps

   End Get

   Set(ByVal value As Boolean)

      Dim val As IntPtr

      If (value) Then

         val = New IntPtr(-1)

      End If

      Dim m As Microsoft.WindowsCE.Forms.Message = Microsoft.WindowsCE.Forms.Message.Create(Me.childHandle, 1025, val, IntPtr.Zero)

      Microsoft.WindowsCE.Forms.MessageWindow.SendMessage(m)

      allcaps = value

   End Set

End Property

The magic value of 1025 was determined from the commctrl.h header file. I should proobably have created it as a const with the same name as the native implementation. One of the great things about VS2005 is that when you build a project with such a control in it, you'll get an automatic addition to your toolbar for it. We haven't added any designer support (outside the scope of this article) but you can set descriptions, categories and the toolbox icon for the control in the usual way. By default you'll get a rectangle with the name of the control which you can position on your form, in many cases this might be good enough. The sample project shows the control dropped on a form with a couple of checkboxes to toggle the properties. Also as a sanity check there is a button labelled Copy which copies the text value from the native control to a regular TextBox - remember we didn't write any code to do that, it's built into Control2 (well in a post-Beta release at least!). The standard behaviour of the CAPEDIT control is to have no border, but you can change this by setting the BorderStyle to BorderStyle.FixedSingle for a plain 1-pixel border.

Control2Example.zip (9.07 KB)

Wait what have I missed, oh yes there are two other useful properties - DesignMode allows you to check if your control is currently in a designer so you can for example not call device specific code, and ModifierKeys is a static property which gives you the current state of the Shift/Ctrl/Alt modifier keys, if your device has a "proper" keyboard.

Stop Press:-

Exhibit A - A CAPEDIT control in a managed app:-

#    |