"Error Loading DLL" if VB Compiled .EXE Has Same Name as DLL

ID Number: Q79598

1.00

WINDOWS

Summary:

If you create a compiled executable program with the same base name as

a dynamic link library (DLL) that is called from the program, an "Error

Loading DLL" message will be displayed when the compiled program

attempts to call the DLL. If the DLL is loaded before the .EXE program

is run (for example, if the DLL is in use from another application)

then the executable program will not run at all.

Similarly, if an .EXE program has the same name as a loaded device

driver (.DRV) and the driver is loaded before you run the .EXE

program, then your executable program will not run. For example, if

you name your executable program TIMER.EXE, it will not run because

Windows has already loaded a device driver named TIMER.DRV.

This behavior is how Windows is designed to operate. It is not a

problem with Microsoft Visual Basic, because the behavior can occur

with any Windows application, and may occur between any two Windows

modules (either from executable programs or DLLs).

This information applies to the Microsoft Visual Basic programming

system version 1.0 for Windows.

More Information:

This behavior occurs because Windows checks, by module name, to see if

a program is already loaded before it tries to execute that program.

If the requested module is already loaded, Windows creates another

instance of that module. Thus, attempting to load a DLL with the same

module name as an already executing program will fail (usually with

the error "Error Loading DLL"), and attempting to start an executable

program with the same module name as an already loaded DLL will not

execute the program.

Because the module name for a DLL is often the same as the name of the

DLL itself (although this can be varied using the LIBRARY entry of the

module definition file used when creating the DLL), and the module name

for a compiled Visual Basic program is the same as the original base

.EXE file name, attempting to load a DLL and a Visual Basic .EXE program

that share the same name will often result in one of the above errors.

To avoid this problem, either recompile the Visual Basic program and

change the .EXE filename, or recreate the DLL, changing the LIBRARY

entry in the module definition file.

Additional reference words: 1.00