Phoning Home, revisited (Matt Gertz)
In my post “M. G. Phone Home,” I discussed how to write a simple phone application for Windows Mobile, using Visual Basic, which accesses the Bluetooth service. What I didn’t discuss was how to deploy it to the phone via CAB. Since I purchased a new phone yesterday (a Samsung Saga, running Windows Mobile 6.1), and I’ve discovered that I need the same app on it, I thought this would be an opportune time to discuss how to do this, since it’s not obvious and slightly different from the distribution of “normal” applications. If you want to follow along, you can find the code at my Temple of VB site (direct release link is here).
(By the way, I’ve modified the app’s code slightly from what I wrote in that previous blog — I have assigned an icon to the application in the project’s properties, because I got tired of seeing the default, non-intuitive icon. If you do this also, make sure that, after doing so, you select the icon in the project’s files and, in the property grid, set its “Build Action” to “Embedded Resource.” If you don’t do that last step, you won’t see the icon on the phone.)
Once you’ve got your phone app completed and debugged (as discussed in the aforementioned blog), choose “File-> Add->New Project.” Select “Smart Device CAB Project” under the “Other Project Types->Setup and Deployment” tree node, and give the project some meaningful name (ResetBluetooth, for example). Select OK so that the project is created.
In the property grid for the new project, make sure that “Manufacturer” and “ProductName” are set however you want them to be, since they will be visible in the program list on the phone.
Now, in the Solution Explorer, right-click the new project and choose “Add->Project Output.” In the resulting dialog, make sure that the first project is selected (the one with the actual code), choose “Primary Output” and click OK. The CAB project will now always contact that project to get its outputs when creating the CAB.
You’re not quite finished, though. You need to add a couple of shortcuts so that you can actually interact with the program on your phone once it’s installed. To do this, bring up the CAB project’s File System Editor if it’s not already visible (right-click the project, choose “View->File System”). In the left-hand pane, you should see “Application Folder” and “Program Files Folder.” “Application Folder” is where the code will end up; don’t change anything about it.
However, “Program Files Folder” is empty, and you need to add a shortcut to the program in it. Select that folder, and in the right-hand pane, right-click anywhere and choose “Create New Shortcut.” In the resulting dialog, navigate into the Application Folder and select “Primary Output from ResetBluetooth (Active)” (or whatever you called your original program). Click “OK.” The Shortcut will be selected for editing, and it will have an atrociously long, descriptive name – give it a more sensible name like “Reset Bluetooth” or something.
You’re still not done, though — you need to add one more folder. Right-click the “File System of Target Machine” node in the left-hand pane and choose “Add Special Folder->Start Menu Folder.” Inside that new folder, add the same shortcut to the primary output that you added in the “Program Files” folder, and give it the same sensible name.
Now you’re done. Build the CAB project, and you’ll find the CAB file in its Release subdirectory. You can copy that over to your phone via the usual ActiveSync mechanism, and then run it on the phone to install it. (I usually map a phone key to that program so that it’s trivial to launch the application – check your phone’s manual for instructions on how to do that.) And that’s it!
‘Til next time,