We find out how to work backwards, and migrate code you no longer have
The import seemed to go well, but the application did not run correctly. The problem is that VB 6.0 and earlier has all sorts of quirks which cause problems when you try and port the code. In this case, the original programmer used VB’s Scaletop and Scaleleft properties to set up a custom coordinate system, and the converter had no idea how to cope with this.
Another issue was that a VB 6.0 control array got converted to a compatibility object called a PictureBoxArray. Objects such as this live in the Microsoft.VisualBasic. Compatibility.VB6 namespace and, although it helps to get code running quickly, it won’t work in the Compact Framework. I converted the code to use a standard ImageList control. At this point the mangled variable names were a nuisance.
Here is a sample of decompiled code:
Function fn00C2(ByVal p007C As4 String, ByVal p007E As String,4 p0080 As String)
As String
Dim l0082 As Integer
Dim l0084 As Integer
Dim l0086 As String
Dim l0088 As String
l0084 = Len(p007E)
l0086 = “”: l0088 = p0080
l0082 = InStr(l0088, p007E)
Fixing the problem with Scaletop and Scaleleft meant going through the code, figuring out what the variables meant and renaming them accordingly. Would it be quicker to rewrite from scratch? In many cases it would. Even so, the decompiled code could be useful as a guide to how the original application worked.
Converting an entire project from VB 6.0 is often not the best approach, because it results in a sub-optimal application that needs a lot of manual tweaking. Another idea is to create a new .Net project, but paste code from the old VB 6.0 project. Visual Studio has a handy tool called Upgrade Visual Basic 6.0 code, which gets you started with porting a block of code.
From desktop to mobile
The final stage was to port the desktop VB.Net project to the Compact Framework.
Create a new Smart Device project, making sure that you target the right kind of
device. Next, copy any non-visual code to the new project. Forms are more
challenging, but you can sometimes save time by copying controls from the old
project to the new, using the clipboard.
Inevitably, the user interface will need to be redesigned for a small screen. The Smartphone format does not have a mouse or a stylus, and there is no such thing as a button control. Anything involving database access will need rethinking, though fortunately Peter Altman’s simple puzzle had none. In this case the main challenge was doing without a mouse.
Developing for the Compact Framework with Visual Studio 2008 is a joy. The latest emulators work smoothly. One thing to note is that closing an application on Windows Mobile does not remove it from memory. If you are debugging, this means that Visual Studio continues in debug mode. The solution is to open the Memory applet on the emulator and terminate the application instance.
Deploying to Windows Mobile
First, your users will need to install the Compact Framework runtime. The latest
version is 3.5, though version 2.0 is smaller and may be all that you need. This
can be downloaded as a Windows Installer setup. Run the setup with the device
connected, and it will be installed automatically.
To create a CAB file for your application, add a Smart Device CAB Project to your Compact Framework solution, and add the primary output from the application to the CAB project. Right-click the primary output in the Application Folder and choose Create Shortcut to add a shortcut for the device. Now build the CAB. Users can install by copying both the CAB and the generated .inf file to their device and running it.
Resources
A
demo
version of the VB3.0 decompiler can be downloaded.
Deploying .Net Compact Framework applications with .cab and .msi files.
Article tags
Related articles
St Helena, a 'small British village' in the mid-Atlantic, is seeking support and funding for a broadband connection
|
|
|
|
|
Computeractive Excel (2010) Online tutorialPrice: £19.99 |
Computeractive Word (2010) Online TutorialPrice: £19.99 |
Computeractive Powerpoint (2010) Online TutorialPrice: £19.99 |
Angry BirdsPrice: £9.99 |
Back Issue CD-Rom 14 (2011)Price: £15.99 |