Windows Mobile 6 Application File Associations

In order for your Windows Mobile application to be invoked when a user opens a particular file type, you need to create an association between the file type and your application. This is done through registry entries.

I’m developing a Windows Mobile 6 application, so my development environment is Visual Studio 2008. The steps below show how to associate a custom file type (.cstm) to your application.

1. Right click on your CAB project. Select View > Registry

Open Registry Editor on CAB project

Open Registry Editor on CAB project

2. Under HKEY_CLASSES_ROOT add Key “.cstm”

3. Under “.cstm” add String values:

        Content Type        text/cstm
        Default             cstmfile
        PerceivedType       text
cstm Registry Entry

cstm Registry Entry

4. Under HKEY_CLASSES_ROOT add Keys “cstmfile” > “Shell” > “Open” > “Command”

5. Under Command add String value:

        Default             ""%InstallDir%\CABExample.exe"" %%1

Note the double quotes surrounding the path to the exe and the percentage characters. Visual Studio creates an inf file and generates the CAB from that. In order for the inf file to be properly formed we need to escape special characters by adding two special characters for every one we want to appear i.e. “” in Visual Studio becomes ” in the devices registry. %InstallDir% is an exception as that is replaced by the actual installation directory at install time.

Open Command Registry Entry

Open Command Registry Entry

6. Under HKEY_CLASSES_ROOT add Keys “cstmfile” > “Shell” > “OpenDoc” > “Command”

7. Under Command add String value:

        Default             ""%InstallDir%\CABExample.exe"" %%1
OpenDoc Command Registry Entry

OpenDoc Command Registry Entry

When you build your project, the following should appear in your inf file:

[RegKeys]
"HKCR",".cstm","Content Type","0x00000000","text/cstm"
"HKCR",".cstm","Default","0x00000000","cstmfile"
"HKCR",".cstm","PerceivedType","0x00000000","text"
"HKCR","cstmfile\Shell\OpenDoc\Command","Default","0x00000000","""%InstallDir%\CABExample.exe"" %%1"
"HKCR","cstmfile\Shell\Open\Command","Default","0x00000000","""%InstallDir%\CABExample.exe"" %%1"

When you install the CAB file on the device, the registry entries will be made and your application will be associated with the file type.

This entry was posted in Programming and tagged , , , . Bookmark the permalink.

One Response to Windows Mobile 6 Application File Associations

  1. Good article. I’m also in the process of developing a WM application. I’m going to keep this article in mind. Thanks.

Leave a Reply

Your email address will not be published. Required fields are marked *