Archive

Archive for the ‘Mobile Development’ Category

Mobile Development Missing in Visual Studio 2010

June 13th, 2010 Christian Etter No comments

VS 2010 is out for some time now. Off course it brings some useful new features. Shure it needs more resources and does not run as quick as the 2008 version, that’s kind of what everyone would expect. However it carries quite a bad surprise for mobile developers….

Low and behold, support for smart device dev is gone!
MSDN is quite clear about it: “Visual Studio 2010 does not support mobile application development for versions of Windows Phone prior to Windows Phone OS 7.0.

That’s quite a bummer. Hard to believe… why would I have to license a legacy IDE to develop software for state of the art mobile operating systems? Perhaps even license two IDEs?

With this in mind, it doesn’t surprise Android is gaining market shares…

Do You have Code Pages? And if not, how many?

November 13th, 2009 Christian Etter No comments

The code page system is a means of representing extended character sets in binary form without leaving the 8 (or 7) Bit based storage and API conventions. There are more than a hundred different code pages, and depending on your system, more or less are supported by the Win32 API.

If you are planning to handle different encodings within your application, it might be useful to know which code pages are available on your system, so you can encode/decode text based on them. Not every System supports every code page though. Just recently I found that an English Windows Mobile 5 would support CP 1252, but not the (very common) Latin-1 character set.
Especially when converting from or to some less common code pages it can be worthwhile to check whether or not there is built in support available.

To enumerate all the installed Code Pages, you can use the EnumSystemCodePages API. It accepts a callback function as a parameter and a flag that specifies whether to enumerate all installed or all supported code pages. Although the docs are not clear about the latter, it seems that the installed code pages are the pages which are ready for conversion, while the supported code pages seem to contain also pages which fail to convert any characters.

Strangely, the callback function gets called with the code page number in string representation, so you might want to do  a _ttoi() in order to get the code page number in use with other APIs.

CAtlArray<CPINFOEX> asCodePagesInstalled;
 
BOOL CALLBACK EnumCodePagesInstalledProc( LPTSTR szCodePageString )
{
    CPINFOEX cpInfoEx;
     if ( 0 != GetCPInfoEx( _ttoi( szCodePageString ), 0, &cpInfoEx ) )
         asCodePagesInstalled.Add( cpInfoEx );
    return TRUE;
}
//...
EnumSystemCodePages( EnumCodePagesInstalledProc, CP_INSTALLED );
//...

It is difficult to determine the lowest common denominator of all code pages supported on every system, and it gets even more complicated when Win 9x or mobile versions need to be supported. So in case your application will demand more than just the bare minimum conversions, you might want to resort to an external library, such as ICU or libiconv.

.NET: Limiting a Program to a Single Instance

March 12th, 2009 Christian Etter No comments

Windows Mobile comes with an internal instance counter that will switch to an already existing window if a program is started more than just once.

Windows CE is lacking such a feature, but it is relatively painless to implement using P/Invoke and events.

public class SingleInstance : IDisposable
{
    [DllImport( "Coredll.dll", SetLastError = true )]
    static extern IntPtr CreateEvent( IntPtr ptrAlwaysZero, bool bManualReset, bool bInitialState, string lpName );
 
    [DllImport( "Coredll.dll", SetLastError = true )]
    static extern int CloseHandle( IntPtr handle );
 
    private IntPtr Handle = IntPtr.Zero;
 
    public bool IsSingleInstance { get { return this.Handle != IntPtr.Zero; } }
 
    /// <summary>A running program is identified by an already existing event that is named the same as the executable path.</summary>
    public SingleInstance() : this( Assembly.GetExecutingAssembly().GetModules()[ 0 ].FullyQualifiedName ) { }
 
    /// <summary>Accepts a single string as a parameter.</summary>
    public SingleInstance( string sEventName )
    {
        this.Handle = CreateEvent( IntPtr.Zero, true, false, sEventName );
        if ( Marshal.GetLastWin32Error() != 0 )
            Dispose();
    }
 
    public void Dispose()
    {
        if ( this.Handle != IntPtr.Zero )
            CloseHandle( this.Handle );
        this.Handle = IntPtr.Zero;
    }
}

You should make use of this class as early in the program as possible, e.g.

static class Program
{
    [MTAThread]
    static void Main()
    {
        using ( SingleInstance si = new SingleInstance() )
            if ( si.IsSingleInstance )
                Application.Run();
    }
}

Use of the above code is not restricted to Windows Mobile though. You could also use this snippet for regular Windows programs, just remember to replace the dllimport for Coredll.dll to kernel32.dll.