Simple clear advice in plain English

How to modify applications without the code

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

Reader Comments

   

Add your comment

All fields must be completed. Your email address will not be displayed or used to send marketing messages.

All messages will be checked by moderators before appearing on the site.

See our Privacy Policy for more information.

Related articles

Make your own media player in Visual Basic

How to play an audio file in Visual Basic

Hands on: Virtual Basic in 2008

Find out what the new year holds for Visual Basic programmers

Hands on: Master the Office 2007 Ribbon

How to make your macros work with Office 2007

Question & Answer

Q.Why are some of the keys on my keyboard doing strange...

> Read the answer

Q.Is my phone’s Bluetooth any use?

> Read the answer

Q.Can I switch boot drives so that I can work on older...

> Read the answer

Best deals on the web

img

Apple iMac 21.5" (MC309)

£926.40- Buy it now

img

Dell Inspiron 620 ST Intel Core i3-2100 3.10GHz / 3GB / 500GB / DVDRW / Win 7 Home Premium

£329.00- Buy it now

img

ZooStorm 7877-1023

£386.38- Buy it now

Latest issue & subscription deals

Poll

Are you concerned about viruses that target mobile phones?

Jargon Buster

Computing terms explained in plain English

Router

A device used to connect more than one computer or other device to the internet.

Great shopping deals from Computeractive