Blog

  • Useful new MessageWindow feature

    Earlier in the Beta for Visual Studio 2005 I submitted a product suggestion to support a very common scenario with the MessageWindow control, and I was delighted to find that in the July CTP it has been implemented.


    The MessageWindow class is provided as a mechanism to receive incoming windows messages and has become a key part of the .NETCF developers interoperability toolbox. .NETCF v2.0 extends the options we have available with new functionality such as support for passing callback functions into native code and COM interop. However there are still times when we will need the humble MessageWindow. One of the first tasks with using the MessageWindow is how to tell the sender where to send the messages. In some cases this involves passing the handle (HWND) of the MessageWindow in via a P/Invoke call, the other common way to identify a MessageWindow is by setting the text and using FindWindow.


    This neatly brings me back to the new feature in question. In v1.0 you had to override the WndProc and add your own handler for WM_GETTEXT (and optionally WM_SETTEXT) in order for your MessageWindow to have a caption. .NETCF v2.0 adds the Text property making life that little bit easier. Just set the Text property to something uniquely identifiable for your application, then you can use FindWindow from your native code to get the handle (HWND) of the MessageWindow and start sending messages to it.

  • One-handed Pocket PC Applications

    Mark has posted the final version of his MSDN article on designing for stylus-free usage on Windows Mobile. This covers both what you get for free in .NETCF v2.0 for navigating around forms with the d-pad and also what you can do to make some of the other intrinsic controls behave. Mark’s sample code includes wrappers around these “badly behaved” controls such as the DateTimePicker.

  • Service Packs and Fixes

    In order to determine all the known issues with .NETCF v1.0 and which Service Pack contained the fix, you would need to look through the fix list for each of the Service Packs in turn. For ease of reference I copied the three fix lists from SP1,2 and 3 and categorised them into the following table. The “o”s indicated in which service pack the issued was resolved. Below it is a table showing which version is preinstalled on the various Windows Mobile devices which have had .NETCF in ROM.




























































































































































































































































































































































































































































































































































































































































































































      RTM SP1 SP2 SP3
    Defects        
             
    Improved code cache performance and memory utilization on ARM processors   o o o
    Parsing of Numeric values is not working correctly on some locales (specially affects VB scenarios)   o o o
    App would not launch properly if it were already running and showing MessageBox when the user navigated out to Home   o o o
    Improved resource loading performance     o o
    Minor GUI performance improvements     o o
    Added support for new Smartphone languages: Finnish, Czech, Romanian, Slovakian, Norwegian, Hungarian, Polish, Turkish, Russian     o o
    Transitions between managed and native code can cause memory leaks on ARM platforms       o
    Stack corruption can occur on ARM platforms when local variables are created but never used       o
    Invoking a multicast delegate from a catch handler throws a MissingMethodException on ARM platforms       o
    Command line arguments containing double byte characters are truncated to a single byte.       o
    Memory corruption can occur on devices that have the native security model enabled and both .NET CF V1 SP3 and a pre-release version of .NET CF V2 installed.       o
    Deadlocks can occur when running under severe resource constraints.       o
    Data Misalignment occurs on Decimal fields in MIPSIV devices.       o
             
    Microsoft.WindowsCE.Forms        
    InputPanel: EnabledChanged Event fires inspite of setting the enabled property to the same value.     o o
    InputPanel: Setting the InputPanel.Enabled property when the form is closing throws an exception     o o
             
    System
    Double: conversion of 0.0F to a string and results in a memory leak     o o
    String: Native exception while calling String.Intern()   o o o
    Type: System.Type.GetType(string) fails to load types that reside on external assemblies if those assemblies are not already loaded   o o o
           
    System.Data
    DataRowCollection.Find Method Returning Incorrect Row   o o o
    DataRowCollection.Find() method throws wrong exception     o o
    DataSet: Improved performance of many data tasks, including populating DataSets, searching DataTables, DataSet.ReadXml() method when a schema is used, finding and indexing operations, setting DataSet.EnableConstraints property “>DataSet: Improved performance of many data tasks, including populating DataSets, searching DataTables, DataSet.ReadXml() method when a schema is used, finding and indexing operations, setting DataSet.EnableConstraints property      o o
    DataSet: Data is missing or loaded incorrectly by DataSet.ReadXml() in some cases.       o
    Fixed crash when SQLClient or SQLServerCe is installed     o o
           
    System.IO
    BinaryReader: BinaryReader.ReadBytes() returns less bytes than asked   o o o
           
    System.Net
    Improved network media sense / connection management experience   o o o
    HttpClient: Authentication state handling errors in http client   o o o
    HttpClient: Http client not using credentials from supplied proxy object   o o o
    HttpWebRequest: Fixed erroneous parsing of HttpWebRequest response stream     o o
    Socket: Force tear down of sockets after dialup disconnect   o o o
    Socket: An uncatchable ObjectDisposedException is thrown when the server closes the socket connection.       o
           
    System.Net.IrDA
    IrDAClient.DiscoverDevices device names garbled     o o
           
    System.Web.Services
    Web services: Compatibility issues   o o o
    Web services: Problem receiving empty arrays mixed with other data   o o o
    Web services: InvalidOperationException when polymorphic type is returned and in the same namespace as the service   o o o
    Web services: Not correctly handling the default values that VB creates for enums when using the DefaultValue attribute   o o o
    Web services: After repeatedly canceling asynchronous web request, all web service calls fail     o o
    Web services: An XmlException is thrown when deserializing a qualified name that has no prefix and there is no default namespace defined     o o
    Web services: Incorrect handling of null headers in SOAP messa     o o
    Web services: A NullReferenceException is thrown when a Web Method returns an empty array using the xsi:Nil attribute       o
    Web services: Modifying the SoapClientMessage.ContentType property does not modify the Http requests ContentType header.       o
    Web services: An ObjectDisposedException is thrown when a asynchronous web request is aborted before the response is received.       o
    Web services: Any array containing one or more elements is not sent to the Web Service correctly.       o
    Web services: An application may hang when invoking a Web Method that uses multiple XmlElementAttributes on a single argument, member or property.       o
    WebRequest.Proxy doesn’t allow spaces in the URL   o o o
           
    System.Windows.Forms
    Memory leak in the NumericUpDown, DomainUpDown, ComboBox and TextBox controls     o o
    The Focus method does not work correctly for the NumericUpDown and DomainUpDown controls     o o
    Auto scroll – scrollbars aren’t removed until control is inside bounds of scrollbars   o o o
    Auto scroll – with control sitting bottom left, should get both scrollbars when control moved over right edge   o o o
    ContextMenu: Support raising context menus from assigned hardware key, Pocket PC     o o
    ContextMenu: Fixed TreeView issues on Pocket PC 2003     o o
    ContextMenu: Fixed side effects on controls like Scrollbar and Label     o o
    ContextMenu: erroneous functionality when bound to ListBox     o o
    ContextMenu: Showing a context menu on Pocket PC for a textbox unselects the selected text in the textbox     o o
    ContextMenu: Empty ContextMenu on Pocket PC should not pop up     o o
    Control: Added support for ForeColor &/or BackColor for Button, Checkbox, ComboBox, DomainUpDown, Label, Listbox, ListView, NumericUpDown, RadioButton, Trackbar, TreeView     o o
    Control: If a focused control property is changed while the application is in the background it loses its focus   o o o
    Control: Don’t get GotFocus Event for first control in form   o o o
    Control: Focus should move to the next control when the current control with the focus gets disabled   o o o
    Control: Extend keyboard events to be enabled on all controls (Control.KeyUp, KeyDown, KeyPress)     o o
    Control: Improved Control.Enabled and Control.Parent property changing performance     o o
    Control: Native Exception occurs when using the get accessor for Control.Capture     o o
    Control: Invoke on a disposed control hangs the application.       o
    Form: ControlCollection Memory leak   o o o
    Form: Improved performance of Controls property   o o o
    Form: Tab support for Pocket PC based on Z-Order     o o
    Form: does not get the focus when all controls are removed from the form     o o
    Form: Navigation bar flickers when new form is being loaded     o o
    Form: ObjectDisposedException occurs when DataBinding a control to a form shown via Show()     o o
    Form: OK button eventually goes away when re-using recycled form for ShowDialog(     o o
    Form: Scrollbars should go away when app 100% client sized control is returned back to 100% inside client area   o o o
    ImageList: Unexpected exception while adding an image to an imagelist on an Hx4700 and hx4705       o
    ListView control allows setting the text alignment of its first column to HorizontalAlignment.Center and HorizontalAlignment.Right   o o o
    ListView: The Text property of a ListView column is reset to “” when removing the column from the ListView and then adding it back.     o o
    ListViewItem.Checked property always returns false if the CheckBoxes property of the listview control is set to false   o o o
    MainMenu: Support menu hotkeys on Pocket PC     o o
    MainMenu: InputPanel Button disappears from MainMenu on Pocket PC 2002     o o
    MainMenu: SIP button does not go away when the toolbar control is removed from a form that does not have a menu     o o
    ProgressBar: Setting the Minimum and Maximum properties of a progressbar no longer crashes the application.       o
    RadioButton: Native exception thrown while setting the Checked property to false   o o o
    ScrollableControl: thumb in wrong position after setting AutoScrollPosition   o o o
    ScrollableControl: throws not supported exception setting AutoScroll=false   o o o
    TextBox: Application terminates with a first-chance exception in gwes.exe when typing quickly in a textbox   o o o
    ToolBar: Tool Bar’s on Windows Mobile 2003 SE no longer lose their images when removed from the form.       o
             
    System.Xml
    XmlQualifiedName objects are corrupted if the namespace of the data is the same as that of the service   o o o
    XmlTextReader performance improvements     o o
             
             
    Devices
    Pocket PC 2003 o r r r
    Smartphone 2003   o    
    Pocket PC 2003 Second Edition     o r
    Smartphone 2003 Second Edition     o  
    Windows Mobile v5.0 Pocket PC       o
    Windows Mobile v5.0 Smartphone       o
    r = Available via RAM install        

  • Making the SDK Documentation more discoverable

    I like John Kennedy‘s proposed SDK TOC for Windows Mobile. And since the sample contains valid links, I was surpised at the amount of content I found which I’d not been able to locate before 🙂


    While there will always be cases when organising content like this you could end up in heated debates about whether article x belongs in category y or z, I believe it’s a definate improvement and gives better visibility of the scope and content of the SDK documentation. I particularly like the fact that Whats New is the first category with itemised details for each update – the SDK documentation has already received two batches of updates.


    Update: I’ve realised there isn’t any Telephony content on this contents page. It would be good to have an entry for Telephony (which is an important part of most Windows Mobile devices) and it should link through to TAPI, Phone, SMS and SIM topics.

  • All These New Devices

    There has been a lot of activity recently on new Windows Mobile 5.0 devices, in a few cases official announcments, in some cases details leaked through common sources such as the FCC site where products sent for testing are publically detailed.


    One of the interesting models to be revealed has been discussed by WallabyFan, with the original scoop at the register. The unique feature of this device is that it is the first Windows Mobile Smartphone to feature a built in GPS. The feature has previously been available on a small number of Pocket PC devices, most recently in the iPaq 65xx range.


    HTC are busy with Pocket PC devices in the form of the Universal, and the Wizard – successor to the Magician (iMate JAM and equivalents), and also new Smartphone models such as the Tornado – a WiFi equipped Smartphone.


    All in all it looks like a lot of exciting new devices will bring Windows Mobile 5.0 to the market place.

  • Functionality in InTheHand.WindowsMobile.Forms

    As has already been shown with some of the other libraries in WindowsMobile In The Hand, the object model is generally designed to follow the Windows Mobile 5.0 APIs. There are a few examples where new functionality is exposed which is not found in the WM 5.0 APIs, some of which was designed specifically to complement Windows Mobile 5.0.


    In the case of the Forms assembly, none of the WM5.0 forms are supported, this is because functionality such as CameraCaptureDialog and SelectPicture dialog rely on new functionality in the underlying OS – prior to WM 5.0 each OEM implemented their own camera support.


    However in WindowsMobile In The Hand, a few new pieces of forms related functionality are added:-



    The MessageBox is designed to provide a softkey-enabled message box for Windows Mobile 5.0 Pocket PCs (although it can also be used on prior versions). When used in a Smartphone project it uses the standard compact framework implementation, on a Windows Mobile 5.0 Pocket PC it produces the following:-



    It’s been designed to follow the Smartphone experience so you can provide the same user experience on both platforms. It supports a full range of overrides for the Show method to specify buttons, icon etc. Here the MessageBoxIcon is used to draw a watermark image on the dialog, similar in spirit to the themed icons which are used on the Smartphone equivalent.


    MobileDevice provides a few helper methods to reset the device, and get the platform type identifier e.g. PocketPC or Smartphone.


    MobileKeys provides a mapping between the device specific key constants (as defined in winuserm.h) and the desktop key codes, so all of the members are of type System.Windows.Forms.Keys.


    OpenFileDialog is built specifically for Windows Mobile 5.0 Smartphone and matches the System.Windows.Forms version available in Pocket PC projects. Again if used in a Pocket PC project it utilises the existing implementation in System.Windows.Forms. It will currently raise a NotSupportedException if used on a Smartphone 2003 device.

  • Windows CE Services and Compact Framework

    Neither .NETCF v1.0 or v2.0 will support runtime hosting, this means it’s not possible to write a service in managed code which will run within the Services.exe process. However it is often useful to be able to query and manipulate other system services from managed code.


    An example of this is where a system service needs to be stopped so that you can access some hardware – such as the OBEX listener service on Windows Mobile which opens the Infrared port. With this scenario in mind I set about wrapping some of the CE functionality for managing services, using the desktop framework as a model.


    The resultant library – InTheHand.ServiceProcess.dll is designed as a subset of System.ServiceProcess.dll – this is the assembly which is added as a reference to your project when you create a windows service project with the desktop framework. The library includes a single class ServiceController which is created with the identifier of the service you which to attach to. Under Windows CE these services have an identifier in the form of a device name e.g. AAAN: where AAA is the prefix, often providing a clue as to the purpose of the service, and N is a numerical index. Returning to our example of OBEX the service is called OBX0:. If you don’t know the name of a particular service you can either trawl through the registry under HKLMServices, or better still call the ServiceController.GetServices static method. The final consideration is to ensure you close/dispose the ServiceController when you have finished working with it. Our OBEX shutdown code looks like this:-


    ServiceController scObex = new ServiceController(“OBX0:”);
    scObex.Stop();

    while(scObex.Status!=ServiceControllerStatus.Stopped)
    {
        System.Threading.Thread.Sleep(1000);
    }

    scObex.Close();


    Notice that the WaitForStatus method isn’t supported so in this case we periodically check the status while sleeping. If we weren’t bothered when the service shutdown you could leave out this section, even when you call Close() to close our handle to the service it will continue with it’s action and shutdown in it’s  own time.


    In terms of platform support, this services.exe model is supported on CE.NET 4.x and above so this includes Windows Mobile 2003 and above.


    You can download the library here:-


    http://www.inthehand.com/Services.aspx

  • Bluetooth COM Ports On Windows CE

    Greg Scott from the Windows CE Networking team has posted an interesting article on how Bluetooth Virtual COM ports are implemented on Windows CE.


    Alongside the native code to setup a port, there are some details on the improvements in Windows Mobile 5.0 which now includes UI options to set both incoming and outgoing ports and is integrated into the bonding/pairing process. This means that OEMs no longer need to produce their own individual applets to expose this functionality.


    For managed code the Bluetooth.NET library wraps this functionality with the BluetoothSerialPort class.

  • Restricting Pim Item Collections

    This applies equally to WindowsMobile In The Hand and the Windows Mobile 5.0 APIs. On the collection classes there exists a Restrict method which returns a subset of the collection matching your search query. You can use the resulting collection to databind or otherwise enumerate over.


    The query language used is similar, but not the same, as SQL: if you imagine that what you are entering here is just the WHERE clause of a query you will not be far off. The key rules to follow are:-



    • Field names must match exactly – refer to the Properties of the Appointment, Contact and Task class for valid field names
    • Field names must be enclosed in square brackets e.g. [MobileTelephoneNumber]
    • You can combine multiple expressions with AND and OR
    • Supported operators are < (Less Than), <= (Less Than or Equal To), > (Greater Than), >= Greater Than or Equal To), = (Equals), <> (Not Equals)
    • Items without the property set will not be returned in a query. So if you set a query of [BusinessAddressCity] = “London” it would not return items without the business address city present even though these are not London.
    • You can use this knowledge to form a query to return all records where the property is set with [PropertyName] <> “” as all items with the property set will match this pattern.

    You can return a full contact list for all items with a mobile number using this code:-


    os = new OutlookSession();

    PimItemCollection pic = os.Contacts.Items.Restrict(“[MobileTelephoneNumber] <> “””);

    listBox1.DataSource = pic;


    listBox1.DisplayMember = “FileAs”


    This example bind the collection to a control, the list will show the contact name only but you’ll be able to retrieve the Contact object from the SelectedItem property of the list box to use it’s other properties (e.g. the mobile number).


    For Windows Mobile 5.0 you can use the new ChooseContactDialog which features a RequiredProperties property so you can easily setup the dialog to show only relevant items.


    Update: Here is the VB equivalent:-


    os = New OutlookSession
    Dim pic As PimItemCollection = os.Contacts.Items.Restrict(“[MobileTelephoneNumber] <> “ & Chr(34) & Chr(34))
    ListBox1.DataSource = pic
    ListBox1.DisplayMember = “FileAs”


     

  • Manually run Windows Mobile 5.0 SDK script

    Some users may find that after installing the Windows Mobile 5.0 SDKs, although no errors were reported, they just don’t show up in the Visual Studio 2005 create project dialog. The reason for this is that sometimes the install script which runs near the end of setup gets blocked by anti-spyware or anti-virus software sometimes without even prompting the user.


    The workaround is quite simple, you just need to locate the script and run it from the command line. Locate the folder where you installed the SDK and the Install_files subfolder. Then run the script passing the full path to the SDK and 0 (to install, if you wanted to manually remove you would pass 1). For example if you installed to the default location you’ll need something like this:-


    install_script “C:Program FilesWindows CE Toolswce500Windows Mobile 5.0 Pocket PC SDK” 0