Category: Compact Framework

More on “My” Functionality in Mobile In The Hand 4.0

In the last post on “My” functionality I showed you how to get started adding the My Extensions to your project. In this post I have assembled a detailed tree of all the “My” functionality added in Mobile In The Hand 4.0.

  • My
    • Application
      • Culture
      • Info
        • AssemblyName
        • CompanyName
        • Copyright
        • Description
        • DirectoryPath
        • ProductName
        • Title
        • Trademark
        • Version
      • UICulture
    • Computer
      • Audio
        • Play()
        • PlaySystemSound()
        • Stop()
      • Clipboard
        • Clear()
        • GetData()
        • GetDataObject()
        • GetImage()
        • GetText()
        • SetData()
        • SetDataObject()
        • SetImage()
        • SetText()
      • Clock
        • GmtTime
        • LocalTime
        • TickCount
      • FileSystem
        • CombinePath()
        • CopyDirectory()
        • CopyFile()
        • CreateDirectory()
        • DeleteDirectory()
        • DeleteFile()
        • Drives
        • FileExists()
        • GetDirectories()
        • GetDirectoryInfo()
        • GetDriveInfo()
        • GetFileInfo()
        • GetFiles()
        • GetName()
        • GetParentPath()
        • GetTempFileName()
        • MoveDirectory()
        • MoveFile()
        • OpenTextFileReader()
        • OpenTextFileWriter()
        • ReadAllBytes()
        • ReadAllText()
        • RenameDirectory()
        • RenameFile()
        • SpecialDirectories
          • CurrentUserApplicationData
          • MyDocuments
          • ProgramFiles
          • Programs
          • Temp
        • WriteAllBytes()
        • WriteAllText()
      • Info
        • AvailablePhysicalMemory
        • AvailableVirtualMemory
        • InstalledUICulture
        • OSPlatform
        • OSVersion
        • TotalPhysicalMemory
        • TotalVirtualMemory
      • Keyboard
        • SendKeys()
      • Name
      • Ports
        • OpenSerialPort()
        • SerialPortNames
      • Registry
        • ClassesRoot
        • CurrentUser
        • GetValue()
        • LocalMachine
        • SetValue()
      • Screen
    • User
      • Name

A full online library of class documentation for all this and more is available. For more information about Mobile In The Hand see the product page.

Vibration and Profiles with Mobile In The Hand 4.0

One of the goals of the Mobile In The Hand library has always been to provide a consistent managed API regardless of which specific flavour of Windows Mobile device you are using. One example of this is using the Vibration feature used to alert the user. The APIs are completely different and so we have provided a simple managed API composing of just two static methods:-

InTheHand.WindowsMobile.Forms.Vibrate.Play();

System.Threading.Thread.Sleep(500);

InTheHand.WindowsMobile.Forms.Vibrate.Stop();

 

You generally won’t want to vibrate the device for very long because it would be both annoying, and a battery drain. To avoid holding up your UI thread you can call the methods on a separate thread. Just remember you must call Stop() to turn off the vibration.

Another example of functionality which is implemented differently between touchscreen and non-touchscreen devices are Profiles. Standard Edition devices can feature a number of profiles for different scenarios, touch screen devices have just three – On, Vibrate only and Off. To retrieve all of the available profiles use the following code:-

 

foreach(string profile in InTheHand.WindowsMobile.Forms.MobileDevice.Profiles)

{

MessageBox.Show(profile);

}

You can set the device profile using a call to SetProfile:-

InTheHand.WindowsMobile.Forms.MobileDevice.SetProfile(“Vibrate”);

The name of the currently selected profile is available from the CurrentProfile property:-

MessageBox.Show(InTheHand.WindowsMobile.Forms.MobileDevice.CurrentProfile);

A full online library of class documentation for all this and more is available. For more information about Mobile In The Hand see the product page.

Using Bluetooth Headsets with Mobile In The Hand 4.0

A commonly requested feature is the ability to switch audio to play through a Bluetooth headset device. Mobile In The Hand 4.0 brings this functionality to .NET Compact Framework developers allowing you to play any device audio through a paired headset device. It also includes classes to playback sounds too.

The AudioGateway sample application which ships with the library contains the functionality to playback a sound file and toggle between the device speaker and a headset. The code to perform the switch is incredibly simple:-

private   BluetoothAudioGateway bag = new BluetoothAudioGateway();

The BluetoothAudioGateway exists in the InTheHand.WindowsMobile.Media namespace. A CheckBox control toggles the output using the following code:-

private   void chkGateway_CheckStateChanged(object sender, EventArgs e)

{

 

   if (chkGateway.Checked)

   {

      bag.OpenAudio();

   }

 

   else

   {

      bag.CloseAudio();

   }

}

OpenAudio opens the connection to the headset and sends audio output to it. CloseAudio closes the connection and returns output to the built in speaker. The SoundPlayer class is used to play back a sound file:-

InTheHand.Media. SoundPlayer sp = new InTheHand.Media.SoundPlayer(txtFilename.Text);

sp.Play();

A full online library of class documentation for all this and more is available. For more information about Mobile In The Hand see the product page.

Windows Mobile Provisioning using Mobile In The Hand 4.0

In the last post we saw the new My Extensions template which adds access to new Visual Basic features. In this post we will look at another new item introduced with Mobile In The Hand 4.0 – Provisioning XML. Visual Studio has a rich XML Editor built in, Windows Mobile uses provisioning XML documents for everything from adding a browser favourite through to configuring a new GPRS network. The new template allows you to quickly create an empty Provisioning XML document and includes the schema to ensure your document is valid. Let Visual Studio’s Intellisense help you quickly build a provisioning document. As with the Visual Basic example you start with an existing device project, in this case it can be either C# or Visual Basic. Select Add New Item and choose Provisioning XML from the list:- Add In this example I have called the file AddFavourite.xml (no prizes for guessing what task we will be performing). The document is created with a skeleton provisioning document. Notice the namespace is provided which links to the schema we installed for you. You can now add the required code between the wap-provisioningdoc tags. As you start to type the IntelliSense will suggest valid elements for you based on the schema:-   This makes it very easy to quickly build up a complete document:- You can process a configuration document like this using the ConfigurationManager class. By setting the document as an embedded resource you can use the following code to load it and pass it to the ConfigurationManager:-

Dim xd As New System.Xml.XmlDocument
xd.Load(System.Reflection.Assembly.GetExecutingAssembly().GetManifestResourceStream("VisualBasicDeviceProject.AddFavourite.xml"))
InTheHand.WindowsMobile.Configuration.ConfigurationManager.ProcessConfiguration(xd, False)

After running this code you can check your Internet Explorer Mobile favourites:- For more information about the library see the product page.

New “My” Functionality in Mobile In The Hand 4.0

This blog post will walk through the process of adding the additional “My” functionality added in InTheHand.VisualBasic. To start off, open Visual Studio 2008 and create a new Visual Basic device project (or open an existing one). At this point you’ll end up with a solution window which looks a bit like this. Note the inspired project name in this example:-

 

The next step is to right-click the project and select Add > New Item… from the menu:-

This will bring up the Add New Item window from which you should see MyExtensions among the list. Select this (you can change the default name if required) and click Add.

The new code file is added to the project. You don’t need to edit this and you won’t be interacting with it directly from your code. Your solution window will now look like this:-

 

You can now get on with building your application. Any time you start to type My you’ll see a much longer list of options:-

Application, Computer and User are new items added by this library and provide additional functionality, all remaining a direct subset of the desktop experience. For example I added a button and in the Click handler added this simple code snippet:-

MessageBox.Show(

My.Application.Info.ProductName)

On running the code the Product Name is retrieved from the assembly information:-

 

In a future post I’ll run through the various items available through the “My” syntax. For more information about the library see the product page.

Mobile In The Hand 4.0 Released

Today we put the final touches to Mobile In The Hand 4.0 and have released this latest version of the suite. This is a major reworking of the code and the library is now broken into 10 separate dlls so you only need to deploy the specific functionality you require in a project. We have also added some additional functionality alongside the code libraries themselves to add “My” keyword functionality for Visual Basic users and make it easier to incorporate and edit provisioning XML documents. Over the next few weeks I’ll be posting a number of blog articles to highlight new features and elaborate on some of the less visible features.

Full details of the library are available on the product page.

Get the name of your executing .exe

The Compact Framework doesn’t support Assembly.GetEntryAssembly to determine the launching .exe. You can instead P/Invoke the native GetModuleFileName function like so:-

byte[] buffer = new byte[MAX_PATH * 2];

int chars = GetModuleFileName(IntPtr.Zero, buffer, MAX_PATH);

if (chars > 0)

{

string assemblyPath = System.Text.Encoding.Unicode.GetString(buffer, 0, chars * 2);

}

Where MAX_PATH is defined in the Windows CE headers as 260. The P/Invoke declaration for GetModuleFileName looks like this:-

[DllImport(“coredll.dll”, SetLastError = true)]

private static extern int GetModuleFileName(IntPtr hModule, byte[] lpFilename, int nSize);

The function expects a HMODULE – a handle to a native module. However passing IntPtr.Zero here indicates we want the module which created the process which is our .exe. This code will always return the path of the calling .exe regardless of if it is in a utility dll, or even a GAC assembly located in the Windows folder.