Welcome to MSDN Blogs Sign in | Join | Help

ToddHa's WebLog

Musings, notions, thoughts about technology and software.

News

  • Disclaimer
    The information in this weblog is provided "AS IS" with no warranties, and confers no rights. This weblog does not represent the thoughts, intentions, plans or strategies of my employer. It is solely my opinion. Inappropriate comments will be deleted at the authors discretion. All code samples are provided "AS IS" without warranty of any kind, either express or implied, including but not limited to the implied warranties of merchantability and/or fitness for a particular purpose.
Hello World, Windows Mobile setup style

One of the items that I haven't found a whole lot of talk about online or in books is how to write a custom installer for Windows Mobile, so I'm going to briefly talk about how to set one up.

Why would you want to do this? The reasons seem simple enough, but the reason I ran into this was that I wanted to explicitly check to ensure that the .NET Compact Framework 3.5 was installed on the device before you try to install the application. Note that I don't block you from installing, just let you know that you need it.

My steps assume a couple of things :
- you have Visual Studio installed with the Smart Device programmability and C++.
- you have at least a little knowledge about C++.
- you can use Visual Studio.
- you have an existing solution with a Smart Device CAB project (found under "Other Project Types, "Smart Device CAB project").

Add a new project to your solution. Under "Other Languages", "Visual C++", "Win32 Smart Device Project."

EmptyProject

A wizard will appear. Pick your platform of choice. On the next page, pick the application type of "DLL" and check the "Empty Project" text box. Click finish, and you should end up with something like what's shown.

Right click the Source Files and add a new item. Pick "Module-Definition File (.def)" and enter a name. I picked Exports.def. Open this file and add the following:

EXPORTS

Install_Init
Install_Exit
Uninstall_Init
Uninstall_Exit

Save and close the file. Add another source file; this time make it a C++ File (.cpp). I named mine Installer.cpp. Open and paste the following code. This code defines the 4 exports we defined earlier.

#include <windows.h>
#include "ce_setup.h"

codeINSTALL_INIT
Install_Init(
    HWND hwndParent,
    BOOL fFirstCall,
    BOOL fPreviouslyInstalled,
    LPCTSTR pszInstallDir)
{
    MessageBox(
        hwndParent,
        TEXT("Hello world!"),
        TEXT("Hello world."),
        MB_OK);

    return codeINSTALL_INIT_CONTINUE;
}

codeINSTALL_EXIT
Install_Exit(
    HWND hwndParent,
    LPCTSTR pszInstallDir,
    WORD cFailedDirs,
    WORD cFailedFiles,
    WORD cFailedRegKeys,
    WORD cFailedRegVals,
    WORD cFailedShortcuts)
{
    return codeINSTALL_EXIT_DONE;
}

codeUNINSTALL_INIT Uninstall_Init(HWND hwndParent, LPCTSTR pszInstallDir)
{
    return codeUNINSTALL_INIT_CONTINUE;
}

codeUNINSTALL_EXIT Uninstall_Exit(HWND hwndParent)
{
    return codeUNINSTALL_EXIT_DONE;
}

Now the previous code doesn't do a whole lot. It simply displays a message box when it starts to install. The four hooks are

1. Install is starting.
2. Install has finished.
3. Uninstall is starting.
4. Uninstall has finished.

All of the function definitions are defined in the "ce_setup.h" file we included earlier. For more information, you can go to (for Windows Mobile 5 Pocket PC) %ProgramFiles%\Windows Mobile 5.0 SDK R2\PocketPC\Include\Arm4vi\ce_setup.h). It explains in details all of the different codes you can return and what they mean.

At this point everything the C++ project should build.

We must include the custom setup DLL as one of the items installed. Right click the setup project you have and click View File System. In the Application Folder, Add Project Output of the Primary Output of your C++ project.

Go back to Solution Explorer and click on the setup project. In the properties window, one of the settings is "CE Setup DLL". Click this drop down box and click browse. Select the primary output in the Application Folder and click OK.

Now build and everything should be ready to go! I copied the CAB file over to the emulator and ran it and got the following:

Capture

That should give you a basic starting point for writing custom Windows Mobile installers! Note that I chose the Pocket PC as it traditionally is much less locked down than Smartphone. With a non-one tier Smartphone, there are a few more hoops to jump through.

Fun stuff:

Disclaimer

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Posted: Tuesday, April 22, 2008 2:28 AM by toddha
Anonymous comments are disabled
Page view tracker