Sat

27

Feb

2010

From CA-Clipper to Windows in 5 Minutes

Do you still have old DOS-Programs based on CA-Clipper running on your system? This Howto shows you, how to speed up those programs by compiling them with hmg.

The Problem

Since the introduction of Windows XP, you probably get a 100% CPU-Usage as soon as you start your exe.

 

Even if your application is only waiting for user-input, it keeps your computer busy.

 

I can not fully explain the reason. But Clipper was not designed to be run in a multitasking environment and windows goes through great trouble to emulate a DOS-environment. So now as soon as your old program runs, even the fastest core duo system slows down to a creep. If you run it on a laptop, your batteries are empty quicker than you can say uncle.

Solution: Compile a Windows-friendly exe

But it does not have to be this way.

 

If you still have your source-code, you are lucky. You can compile it almost without any changes and turn it into an application that looks exactly the same, but runs much quicker and consumes only CPU-cycles when it is doing something.

 

There are many Clipper compilers out there. Some of them are even free. 

The compiler: Harbour

Harbour is a great compiler. It will take your Clipper source-code and turn it into C-Code that can be compiled into a binary. You can choose your compiler and there are many libraries that add functions to your program you never dreamt of. It will even run on Linux and Mac-OS.

HMG: A harbour-compiler with batteries included

If you are not interested in Linux and Mac-OS and all the fancy features, you just want an application that installs everything you need. A C-Compiler, binaries and batch files and even a lot of samples.

Such a program exists. It is called "Harbour MiniGUI", or just "hmg" for short. Visit the developers website:

http://harbourminigui.googlepages.com/

You can grab the latest version here:

http://www.hmgforum.com/site/

At the time of writing this post, 3.0.22 is the latest version. It is a 20 MB download. Users at hmgforum.com confirm, that it runs well with Windows Vista and Windows 7.

 

Update: Right now, the current stable version is 3.0.39 if you don't need postgresql-suppprt.

 

hmg 4.0 ist still in alpha-state. It's goal is to port the windows-api based gui to Qt and make it platform-independent. Be patient. It is not ready, yet.

Installing HMG

After you downloaded, the setup file, you can run a regular installer.

 

I recommend installing it into c:\hmg

 

 

Starting the IDE

The installation takes a few seconds. After it is finished, you have everthing you need. Compiler, Linker, Include-Files, etc.

 

You could compile your prg-files on the command-line, but I prefer the graphical IDE. It gives you a glipse into the many additional features you get with HMG.

 

Launch the hmg-ide either from the shortcut on your desktop or the startmenu.

The hmg-ide
The hmg-ide

Start a new Project.

You can place the project into your existing source-code directory on your harddrive. Make sure, you have a copy in case anything goes wrong.

 

The IDE creates a new "Main.Prg" and a new emty form "Main.Fmg". 

Removing Main.Prg and Main.Fmg

HMG is a great tool to build real Windows-Applications. It is abolutely amazingly simple to turn an existing Clipper-Program into a Windows-Program. But for now, we resist the urge to look at all the shiny features.

 

All we want to do is compile our console application.

 

So for now, we don't need the Main.Fmg and Main.Prg. Delete them by selecting them in the Project-Browser and clicking Project - Delete File from the Menu.

Adding your Source-Code to the IDE

Now you have an empty Project. Choose "Modules" in the Project Browser and click on "Project" - "Import File" in the Menu to import your all your prg-files.

 

The first one you choose will be your main-module. That means, it includes the procedure or function that starts the program. You can declare a module as main by clicking "Project" - "Set Module As Main" in the menu.

Console mode

By default, HMG wants to build a Windows-Application. But your old CA-Clipper-code is a console application.

 

So you have to tell the compiler to run in "Console Mode". You do that in the Project Browser in the Configuration-Tab.

Update: If you are using Version 3.0.39, there is noc "Console mode" any more in the "Configuration"-Tab. Don't panik. It still works. Simply add this line to your main .prg-file:

REQUEST HB_GT_WIN_DEFAULT

 

To be more precise, you now have a mixed-mode program. That means, you can already use windows-gui elements wherever you like.

Edit your Code

In some cases, you have to make little adjustments to your code.

 

Most importantly, harbour looks for a function or procedure "Main". If it does not find it, it will not do anything, because it does not know where to start.

 

Clipper also supported the first function to be named like the .prg-file. So open your prg-file with an editor of your choice and rename the main function.

 

The old prg-file will be saved in the codepage 850.

 

My favorite editor is jEdit. It calls the codepage IBM850. If some characters (umlauts, accents, box-drawing-characters, etc.) look funny, click "File" - "Reload with Encoding" - "IBM850".

 

Do not change the encoding. Keep it 850 for your console application!

Run

Compile your code by clicking "Project" - "Run" in the Menu.

 

HMG will build an .exe-file and launch it. So if all goes well, your program starts.

 

The new exe-File is rather large (1-2 MB) compared to an original clipper-exe. But who cares nowadays, right?

 

Here is a screenshot of a sample console application. As you can see, the wait-command does not keep the Processor busy.

Conclusion

This howto demonstrated, that you don't have to through away your old Clipper code and write it in a new language if you want an application that works well on Windows.

 

With hmg you can turn it into a modern harbour-console-program for windows within a few minutes.

What next?

You can now incrementally modernize your program. You might mant to start by replacing ALERT() with msgbox() to see how well it mixes.

HMG opens a lot of possibilities to really take old application to the 21st century.

 

I find it very impressive, that Roberto Lopez managed to extend the xBase Language, so that modern GUI-Controls can be defined in an easy to understand way.

 

Code looks like this:

 

#include "minigui.ch"

Function Main

    DEFINE WINDOW Win_1 ;
        AT 0,0 ;
        WIDTH 400 ;
        HEIGHT 200 ;
        TITLE 'Tutor 10 - Picture Button Test' ;
        MAIN

            @ 10,10 BUTTON PictureButton_1 ;
                PICTURE 'button.bmp' ;
                ACTION MsgInfo('Picture Button Clicked!!') ;
                WIDTH 27 ;
                HEIGHT 27 ;
                TOOLTIP 'Picture Button Tooltip'

    END WINDOW

    ACTIVATE WINDOW Win_1

Return

The IDE helps you build this code by designing your forms in a gui-designer.

 

If you want to know more about HMG, take a look at C:\hmg\SAMPLES and c:\hmg\DOC\hmgdoc.htm (also available online).

 

I found the people over at hmgforum.com very nice and helpful. They helped me when I got stuck and reading the forum gives a lot of insights.

Write a comment

Comments: 34

  • #1

    Hitman (Monday, 22 March 2010 08:28)

    Nice Info!

  • #2

    Micsa (Sunday, 02 May 2010 23:30)

    nice info thanks

  • #3

    edis (Sunday, 05 September 2010 16:42)

    Processor abuse problem was well known and fixed in late Clipper, problem only if you miss source code, perhaps.

    Even though DOS is heading into nowhere, Clipper had advantage to the very late of providing great base for flexible programming, as opposed to much more complicated programming for Windows platform. And relational data access level is still outstanding, making well questionable superiority of SQL. It may be personal, but with demise of Clipper I never had later in hands programming tool, that would match it in productivity, versatility. And there were quite some to work with.

  • #4

    Bicahi Esgici (Wednesday, 26 October 2011 23:41)

    Hi Ricci

    Could you allow me to publishing this very good article in my blog ?

    By noticing the source of course.

    Regards

  • #5

    raumi75 (Thursday, 27 October 2011 09:50)

    Yes, of course!

    I assume your blog is vivaclipper, right? Your blog was an important resource for me, when I was looking for a way to keep my clipper-program alive. I would appreciate it, if you linked back to this article.

  • #6

    Bicahi Esgici (Thursday, 27 October 2011 12:58)

    Thanks Raumi

    First, sorry for name confusion;

    second, thanks to your kind words :)

    Due to some obscure reasons ( in short, "Google pages" is prohibited in my country) my VivaClipper Google page is out of my access :(

    Now I'm struggling move my page to another page. I'm in the beginning and I have too many thing to work on. It's not announced yet.

    Pleas look at copy of your article:

    http://vivaclipper.wordpress.com/2011/10/26/from-ca-clipper-to-windows-in-5-minutes/

    If you like it please notify me your approwal.

    Regards

    --

    Esgici

  • #7

    Bicahi Esgici (Thursday, 27 October 2011 13:22)

    In addition; sorry, but I don't understand the "CA-Clipper" term or "Cl*pper" notation. IMO, CA is only owner of Clipper compiler, not Clipper language.

    What is your opinion ?

    Regards

    --

    Esgici

  • #8

    raumi75 (Thursday, 27 October 2011 18:09)

    It's great to hear that you are building a new site dedicated to clipper. Let's hope they don't start censoring wordpress.

  • #9

    raumi75 (Thursday, 27 October 2011 18:12)

    I am not really happy with the whole naming-issue. "Clipper" and "harbour" are too generic. If you google it, you get all kinds of results. For Search-Engine-Optimization-Reasons, I chose to call it CA-Clipper in this article as I am trying to address people who still use the old Compiler.

  • #10

    raumi75 (Thursday, 27 October 2011 18:34)

    So you can't access http://sites.google.com/site/vivaclipper2/ any more? I just made a mirror by running "wget -m" and zipped it. It is 3,4 MB. Do you want me to mail it to you?

  • #11

    Bicahi Esgici (Thursday, 27 October 2011 20:22)

    You are right in naming-issue. Perhaps I think such way because I hate CA ;)

    Thanks to your proposal about zipped file of my "site"; I have all necessary materials, including zipped full site.

    By the way, you don't noticed your approval on publishing your article; did you seen, and like?

    Regards

    --

    Esgici

  • #12

    raumi75 (Thursday, 27 October 2011 21:35)

    I posted my approval on your blog. Of course you can use the article.

  • #13

    Esgici (Saturday, 29 October 2011 12:09)

    Yes, I seen an answered

    Thanks again

    I'm waiting your further supports to xBase community.



  • #14

    esgici (Monday, 31 October 2011 20:28)

    Hi Raumi

    I changed URL of your article on my blog:

    http://vivaclipper.wordpress.com/category/clipper/articles/

    And instead of duplicate, I published it as a summary and added whole address in your blog.

    IMHO with this way no need to you notify me about modifications and to me re-copying or correcting my copy.

    What is your opinion ?


  • #15

    raumi75 (Tuesday, 01 November 2011 19:17)

    I think, this makes it easier to maintain, when I feel like I have to update something. Thanks for linking here.

  • #16

    Esgici (Tuesday, 01 November 2011 22:41)

    Thanks

    Have you see this post :

    http://hmgforum.com/viewtopic.php?f=19&t=2135#p18313

  • #17

    raumi75 (Wednesday, 02 November 2011)

    Wow, hmgforum links to my blog. I feel flattered. Thanks for telling me.

  • #18

    Esgici (Wednesday, 02 November 2011 18:06)

    You have furthermore :

    http://hmgforum.com/viewtopic.php?f=19&t=2135&start=10

    Congrats !

  • #19

    iliev (Tuesday, 10 January 2012 18:46)

    sorry, but don''e execute module dos/clipper with dows 7 / 64 bitswin

  • #20

    raumi75 (Thursday, 12 January 2012 18:33)

    I use Win 7 64 Bit and it runs well. What hmg-version did you use? Did you include REQUEST HB_GT_WIN_DEFAULT in your .prg file?

  • #21

    Ghost ship (Thursday, 12 April 2012 18:23)

    Great post! Thank you. While I was reading, was traveling about twenty years ago, when I had my first contact with programming, via Clipper and dBase. What good memories!

  • #22

    Eduardo Pintado (Wednesday, 25 April 2012 18:57)

    Great to know there's a chance to upgrade my DOS CA Clipper system.
    Q: Can be the new .exe binaries executed straight from Windows or should be triggered thru the IDE ? Many thanks

  • #23

    raumi75 (Thursday, 26 April 2012 11:41)

    HMG will create an .exe file that runs on Windows. You do not need the IDE to run the binary.

  • #24

    KAILASH (Thursday, 10 May 2012 13:55)

    I was trying to convert my clipper 5.2 app.
    Just after opening screen, I am getting an error
    "dbcmd/2001 workarea not in use DBCLEARFILTER. can u please help? Also, where to find error codes list? Thanks.

  • #25

    raumi75 (Thursday, 10 May 2012 17:09)

    Do you mean after compiling and running your new .exe? That would be a runtime error. Hard to tell what is causing it without looking at your code. Have you placed the .exe file into the same directory as your old, working .exe? Maybe this post will help you:

    http://www.hmgforum.com/viewtopic.php?f=5&t=2169

    The people at hmgforum are very friendly and helpful. There is also a Mailing List (http://groups.google.com/group/harbour-users/) and a Facebook group (https://www.facebook.com/groups/harbour.project/) where you can ask questions.

  • #26

    Boban (Monday, 18 February 2013 22:29)

    Hi, I am using HMG to convert my old ca-clipper apps to windows gui apps. I want to know how to define window for each procedure; in the procedure itself, or to call the procedure when windows initializes?

  • #27

    raumi75 (Tuesday, 19 February 2013 10:13)

    Hi, I am not sure I understand your question. A good start is looking at the many samples in your HMG-folder. I good place to ask such questions is hmgforum.com. The people are very knowledgable, helpful and friendly.

  • #28

    Nick (Saturday, 20 April 2013 09:12)

    Hello, I've converted my old Clipper 5.1 app into Harbour using HMG. I can run now my app, my problem is that when I type in data, the screen scrolls up line by line with every data I input, so I don't see anymore the already typed in data. I use classic contruction lines.
    @ row, col say 'Type in data: ' get some_data
    read
    Any ideas? Thank you.

  • #29

    Tim ODell (Thursday, 13 June 2013 06:42)

    I've installed version 3.1.3 on both Windows 7 and Windows XP, and cannot find an icon for the MiniGui program. Which program to start it, and which directory is it in?
    --Thanks
    PS: I agree completely about newer programs being difficult. I'm still maintaining programs from th 80's that clients love!

  • #30

    raumi75 (Wednesday, 19 June 2013 12:51)

    Depending on the path you declared at installation time, it should be c:\hmg.3.1.3\ide\ide.exe

  • #31

    walt (Thursday, 30 January 2014 23:02)

    is there anything that can be done if I don't have the source code

  • #32

    raumi75 (Tuesday, 04 February 2014 10:53)

    You will need a decompiler. I have no experience with them. Try to google that. You might want to try and ask people in the hmg-forum.com or the official harbour mailing list.

  • #33

    aks (Friday, 21 February 2014 12:21)

    i have build my exe using hmg (minigui) . which is error free. my .exe is not getting executed . i am using Vista OS

  • #34

    Rick451 (Friday, 14 March 2014 06:38)

    I wrote a program for a company in Clipper 5.1 (DOS) in 1990, installed and tested it on their Novell network and that was it. Much to my surprise I got my first call for support in 2009. I couldn't believe that they were still using it on a daily basis after 19 years. They had a corrupted database with errant EOF markers and I had written a program in C to correct that and recover nearly all of the lost data in 1993 so I simply e-mailed them the program and poof no more problems. I have found Clipper to produce extremely well behaved programs under virtually any operating system from DOS through Windows XP, including Lantastic and Novell networks running over DOS as well as Windows networks. I did find that my version of Clipper doesn't trap as many errors as I would like so I usually run the main Clipper .EXE application from a shell written in C+ and return error codes to the shell which can deal with the error and respond accordingly. It works.

  • loading