Confused! "LINK" command???

If you have questions about any aspect of QBasic programming, or would like to help fellow programmers solve their problems, check out this board!

Moderators: Pete, Mods

Post Reply
Posts: 22
Joined: Thu Dec 21, 2006 12:31 am

Confused! "LINK" command???

Post by CDRIVE » Sun Dec 24, 2006 5:20 pm


Below is a copy of the help file that was supplied with I have a suspicion that Hans Lunsing is someone you're all familiar with. Please read it and explain a few things to me. The term "LINK" is used in the instructions as if it were command words, but I can't find it in the QB45 help files or in DOS commands. What am I missing? I read and tried to understand what I could but I'm green. Is "LINK" just a term used to describe the end result of code you write with his files inserted in your program?

Thank you,


To easily use long Win32 filenames in QuickBasic, QuickBasic
Extended (PDS) and Visual Basic for DOS programs

Version 2 (c) 1998 - Hans Lunsing


System requirements
Long filenames can only be used on systems supporting the Win32
protected mode FAT file system, such as Windows 95. However, the
procedures in the unit are structured so that they can also be
used with the short 8.3 names of the old DOS FAT system. So the
same code can be used on both systems. Only the names of the
files handled in the program have to change.

Contents of the package

QbLfn.lib the library for QB 4.5
QnLfn.lib the library for BC 7.1 with near strings
QxLfn.lib the library for QBX and BC 7.1 with far strings
VbLfn.lib the library for VBDOS 1.0 standard edition
MbLfn.asm the assembler source code
MbLfn.bas the basic source sode
Intrpt.asm the source code of the interrupt procedure the include file with declarations
MbLfn.doc this documentation

How to install
Include the file in your programs and modules:


and link one of the libraries with your programs, dependent on
your compiler and on your using near or far strings. With QB 4.5
you must use QbLfn.lib, with VBDOS 1.0 you must use VbLfn.lib,
and with PDS 7.1 you can use QnLfn.lib (for near strings) or
QxLfn.lib (for far strings). Except QnLfn.lib you can link the
libraries into quick libraries for use with the respective IDE's:

LINK /Q QbLfn.lib,QbLfn.qlb,nul,bqlb45;
LINK /Q QxLfn.lib,QxLfn.qlb,nul,qbxqlb;
LINK /Q VbLfn.lib,VbLfn.qlb,nul,vbdosqlb;

You cannot link QnLfn.lib into a quick library because the IDE
of PDS 7.1, QBX.EXE, recognizes far strings only.

Interrupt procedures with the same declarations as Microsoft's
own interrupt procedures are included in the libraries. So you
don't need to merge the libraries with QB.LIB, QBX.LIB or
VBDOS.LIB respectively.

The main function of the library is


It has no arguments. When it is called it first tests if the
system supports Win32 long filenames. If not, it returns FALSE
(0) as a value. If yes, it returns TRUE (-1) and enables the
use of long filenames with most normal QuickBasic and VBDOS file
and directory commands.

These commands accept long filenames after EnableLfn without
more ado:


The commands


normally truncate and capitalize the long file names. However, I
added a function


to the library. Apply it to the file name when using OPEN, BSAVE
or BLOAD, and you will see that long file names are preserved
then. For example:

OPEN Lfn$(LongFileName$) FOR OUTPUT AS #Handle%
BSAVE Lfn$(LongFileName$), Bytes%, Offset%

and that's nice, because these are the most complex commands
working on file names. You can use the same syntax when long
file names aren't enabled. Lfn$ detects if that is the case and
simply returns the given file name then.

When Long filenames are enabled all DOS interrupt &h21 calls
with one or more file names as input are rerouted to the
matching Win32 interrupt &h21 long file name functions. So when
calling the normal interrupt &21 file functions you now are able
to use long file names. Furthermore, the rerouting will have the
result that many libraries not written to use long file names
now can use them!

To disable long file names call


It will be called automatically, however, when the program

Other, more simple, file and directory commands and functions
don't allow long file names. That's why I added long file name
versions of them to the library. They can be used independently
from EnableLfn and can be used in stead of the QB, PDS or VBDOS
versions, also on systems not supporting long filenames. Note
that QB doesn't have CURDIR$ en DIR$, but can use its long
filename replacements. Furthermore I added a function to get
file attributes, and a procedure to set file attributes. They
are new to all flavors of Microsoft Basics.

These are the commands and functions and their long file name


CURDIR$ (not QB) LfnCurDir$
DIR$ (not QB) LfnDirFirst$ (the first call, with arguments)
LfnDirNext$ {next calls, without arguments)
FILES LfnFiles
KILL LfnKill
NAME LfnName
not supported LfnGetAttrib% for getting file attributes
not supported LfnSetAttrib for setting file attributes

All these procedures and functions are defined in the include

Together LfnGetAttrib% and LfnSetAttrib offer the same
functionality as PowerBasic's ATTRIB function and statement.
With LfnDirFirst$ it's also possible to use attributes as a
search criterium, like in PowerBasic. The function always finds
normal and read-only files, but it can also find hidden and
system files, directories, and even volume labels by stating the
appropriate attributes. Possible attributes are:


So by including the directory attribute as a search criterium,
and later testing the attribute of the found files and
directories with LfnGetAttrib%, you can find all subdirectories
in a given directory.

The other long file name commands and functions take the same
arguments as their QB/PDS/VBDOS counterparts, but all arguments
are required. LfnName of course doesn't use the keyword AS. They
also work the same way.

To check if a long file name command or function encountered an
error one of the functions

DOSErr, or

has to be called. Both return the DOS error code. A list of them
is included in appendix A. DOSErrTest resets the error code to
zero. DOSErr doesn't. So error checking works the same as with
ON ERROR RESUME NEXT (in PDS and VBDOS only) for Basic errors.

The DIR$ replacements, LfnDirFirst$ and LfnDirNext$, have some
supplementary functions:

LfnDirAlias$ returns the alias name of the long file name
just returned by LfnDirFirst$ or LfnDirNext$
on systems with long file names.
On other (DOS) systems it just returns an empty

GetFindData returns the contents of the Win32 FindData
structure. In it you can find the attributes,
dates, times and size of the file with the name
just returned by LfnDirFirst$ or LfnDirNext$ on
systems with long file names.

GetFileInfo returns the contents of the DOS FileInfo
structure. In it you find the attributes, date,
time and size of the file with the name just
returned by LfnDirFirst$ or LfnDirNext$ on
systems without long file names, or by DIR$.

You can find the format of both data structures in appendix B.
They are defined as a typed variable structure in the include

There are three more functions in the unit:

LfnSupported% to check if Win32 long file names are supported
without enabling long file names in PowerBasic

DiskFree& returns the free space on a disk drive in bytes

CurDrive$ returns the current drive letter.


When using EnableLfn with QBSwap you must link the assembler
object file MbLfn[q|n|f].obj before QBSwap.obj. If you don't
like extra code staying in memory when swapping you must call
DisableLfn before swapping. After that you can enable long file
names again.

EnableLfn can't be used in conjunction with CHAIN or RUN.

Differences with the first version

It appeared impossible to have two or more files open at the same
time using OPEN with the Lfn$ function. This is fixed.


You are free to use MbLfn32. However the contents of the package

Copyright (C) 1998 by Hans Lunsing. All Rights Reserved.

If you use MbLfn32 on a regular basis I request you to pay an
amount of your own choice to a non-profit organization for the
general benefit, also of your own choice, and to let me know
that by means of a post card. Furthermore I ask you to mention
Mblfn32 in the documentation of programs published by you
in which you used it.

Everything in this package is provided with no warranties
whatsoever, express nor implied, for any functionality or
fitness for a specific purpose. The author will not be held
responsible for any damages whatsoever resulting from the use of
this package, and will not be held responsible if the package
does not perform.

The author

My home addres is:

Hans Lunsing
Klaproos 38
2317 EL Leiden
The Netherlands

phone ++31-71 5232703

e-mail fido 2:500/104.6955


Appendix A. DOS error codes

01: Bad function
02: File not found
03: Invalid path
04: Too many open files
05: Access denied
06: Invalid handle
07: Memory destroyed
08: Out of memory
09: Bad memory block
10: Bad environment
11: Bad format
12: Invalid access code
13: Invalid data
14: Internal error
15: Invalid drive
16: Can't remove current directory
17: Not same device
18: File not found or no more files
19: Disk is write protected
20: Bad disk unit
21: Not ready -> insert disk
22: Bad disk command
23: Data error
24: Bad call format
25: Seek error
26: Unknown media type
27: Sector not found
28: Out of paper
29: Write error
30: Read error
31: General failure
32: Sharing violation
33: Lock violation
34: Invalid disk change
35: FCB unavailable
36: Sharing buffer overflow

80: File already exists
82: Can't make directory entry
83: Fail on INT 24
84: Too many redirections
85: Duplicate redirection
86: Invalid password
87: Invalid parameter
88: Net device fault

Appendix B. File data structures

The Win32 Find Data structure has the following format:

offset contents number of bytes

0 Attributes 4 (long integer)
4 Creation time 8 (2 long integers)
12 Last access time 8 (2 long integers)
20 Last write time 8 (2 long integers)
28 Size in bytes 8 (2 long integers)
36 Reserved 8 (2 long integers)
44 Name 260 (string)
304 Alias name if Name is long
name 14 (string)

MbLfn let the system place dates and times in the old DOS
format. The first word of a time field has the time, the second
word the date, and the next two words are zero.

Name and Alias name are null-terminated strings.

The DOS FileInfo structure has the following format:

offset contents number of bytes

0 Reserved 21
21 Attributes 1 (byte)
22 File time 2 (word)
24 File Date 2 (word)
26 Size in bytes 4 (double word)
30 Name 13 (string)

File date and time are in the standard DOS format. Name is a
null-terminated string.


Post by Anonymous » Mon Dec 25, 2006 11:36 am

Link.exe it's an executable that the quickbasics compilers include in the downloads; it's important; you will use it to merge the .Lib file into the Quickbasic library of your compiler to work using the Mblfn32 into your programs, here it is an explanation that i have about Link:

Link.Exe (Qb, Pds, Vbdos) This is the Segmented Executable Linker used to create executable files, Quickbasic libraries (.qlb), combine object files (.obj) and standard library files (.lib) into a single executable or Dll. Can produce Ms-Dos executable files with up to 1MB. of code and data; for OS/2 and Windows programs, the limit is 16 megabytes. For OS/2, can produce Dlls in addition to executable files (.Exe). Screen short help:
Link @<response file>
Link <objs>,<exefile>,<mapfile>,<libs>,<deffile>
Valid options can be:
/? (not for QB)
/alignment (not for QB)
/binary (only QB)
/dynamic (only Vbdos)
/incremental (only PDS)
/nologo (not for QB)
/nonullsdosseg (not for QB)
/nopackfunctions (only Vbdos)
/oldoverlay (only Vbdos)
/onerror (only Vbdos)
/packfunctions (only Vbdos)
/padcode (only PDS)
/paddata (only PDS)
/pcode (only Vbdos)
/pmtype (not for QB)
/r (only Vbdos)
/tiny (not for QB)
/warnfixup (not for QB).
Last edited by Anonymous on Mon Dec 25, 2006 12:14 pm, edited 2 times in total.



Post by Anonymous » Mon Dec 25, 2006 12:03 pm

Possible Bug: when i was using the Mblfn32 the Dir$ function included in the program sometimes it did repeat counting few more files of the included files in the working directory.

For example, when a directory had a thousand files could count I,O5O files. But i was only working Uppercasing and Lowercasing the names of the files, so, easily the Bug could be mine, maybe i forgot the hidden and system files.
Maybe this is a tip that you would like to test.

Posts: 22
Joined: Thu Dec 21, 2006 12:31 am

Post by CDRIVE » Mon Dec 25, 2006 6:33 pm

Whoa! That was "DUH!" moment for me! LINK.exe in my QB45 folder. What the hell was I thinking? I never made the connection, though I knew it was there. BTW, I've asked Pete if he would include the link to Hans Lensing's site here. Has told me he's going to update the site and add descriptions of his downloads.

Thank you so much for your help.


Post by Anonymous » Tue Dec 26, 2006 4:03 pm

Happy New Year, Cdrive.

Post Reply