16bit Custom Stubs
OK, so I have to admit this probably isn't much use to anybody, seeing as most people don't write 16-bit applications anymore. And even fewer people have to worry about having their program's run at a DOS prompt. But I think it's a neat trick, so I'm going to tell you anyway :)
All 16bit and 32bit Windows applications contain a DOS 'stub' program. When you run a Windows application at a DOS prompt (a real DOS prompt, like DOS 6.22, not a command prompt inside Windows) it's the DOS program that displays the message "This program requires Microsoft Windows". Except for Clarion applications(and old protected-mode DOS JPI applications), which normally say something like "This program cannot be run in DOS mode"
By using a compiler pragma in the project file you can change the DOS stub program of a 16bit Clarion application to be anything you want. Unfortunately it doesn't work for 32bit programs, because the 32bit linker ignores the compiler pragma. (As a matter of interest, the 32bit linker contains the entire DOS stub internally - when you compile a 32bit Clarion application, the linker reads the stub from inside the C5xLPEX executable and writes it out to disk as the first bytes of the new executable)
The project file setting you need is this:
#pragma link_option(stub=>DOSSTUB.EXE)
Don't worry if you can't find it documented in any Clarion manuals. The only place I was able to find it was in Chapter 4 "Pragmas" of the JPI / TopSpeed Developer's Guide. When you do include it in a hand-coded project file ( you can't use the project editor in the Clarion IDE, it throws up a project syntax error message ) you should end up with something resembling the following:
#system win #model clarion lib #pragma link_option(stub=>DOSSTUB.EXE) #pragma debug(vid=>full) #pragma debug(line_num=>on) #pragma check(stack=>on) #pragma check(nil_ptr=>on) #pragma check(index=>on) #compile "testexe.clw" #link "testexe.exe"
This will have the effect of replacing the standard DOS stub with the application named DOSSTUB.EXE. The stub program can be anything you want - a simple message, an editor, a game or a virus. Back in the days when I did have to worry about writing 16bit code, my custom Modula-2 stub looked like this:
MODULE ABXSTUB;
IMPORT Lib,Str;
TYPE STR512 = ARRAY [0..511] OF CHAR;
VAR param : STR512;
result : CARDINAL;
BEGIN
Lib.ParamStr(param,0);
result:=Lib.Exec('WIN',param,NIL);
Lib.SetReturnCode( SHORTCARD(result) );
END ABXSTUB.
For those of you unfamilier with Modula-2, or just too lazy to work out what the code does, it's a simple application that runs Windows from the DOS prompt and passes the name of the executable of the first parameter. In other words, when you try to run the application from the DOS prompt, it won't display a nasty error message; instead, it'll start Windows for you and run the application at the same time.
Back to the home page