PRB: Error in loading DLL When LIBRARY & File Names DifferentID: Q98309
|
The "Error in loading DLL" error message occurs if you call a DLL and the LIBRARY name of the DLL is different from the filename.
This behavior is by design. Visual Basic ensures that the LIBRARY name and
filename of a DLL match. If they don't match, Visual Basic generates the
"Error in loading DLL" error.
Visual Basic version 3.0 does not require that the LIBRARY name and the
filename be the same for a DLL. However, unless you are designing a DLL
specifically to be called from Visual Basic version 3.0 or some other
application not written using Visual Basic, we recommend that you use the
same name for both the LIBRARY name and filename of a DLL.
When creating a Windows DLL, you must specify the LIBRARY name of the
DLL in the module-definition (.DEF) file for the DLL. In order to call
any procedure contained within the DLL from Visual Basic, the LIBRARY
name given in the module-definition file must be the same as the
filename for the DLL.
#include <windows.h>
VOID FAR PASCAL test ( VOID );
VOID FAR PASCAL test ( VOID )
{
//The contents of any procedure in the DLL is not important
//Define this procedure to be called from Visual Basic
return;
}
//----------------------------------------------------------------
// Initialize library. This routine is called when the first
// client loads
// the DLL.
//----------------------------------------------------------------
int FAR PASCAL LibMain
(
HANDLE hModule,
WORD wDataSeg,
WORD cbHeapSize,
LPSTR lpszCmdLine
)
{
// Avoid warnings on unused (but required) formal parameters
wDataSeg = wDataSeg;
cbHeapSize = cbHeapSize;
lpszCmdLine = lpszCmdLine;
return 1;
}
//----------------------------------------------------------------
// WEP
//----------------------------------------------------------------
int FAR PASCAL WEP(int fSystemExit);
//----------------------------------------------------------------
// Performs cleanup tasks when the DLL is unloaded. WEP() is
// called automatically by Windows when the DLL is unloaded (no
// remaining tasks still have the DLL loaded). It is strongly
// recommended that a DLL have a WEP() function, even if it does
// nothing but returns success (1), as in this example.
//----------------------------------------------------------------
int FAR PASCAL WEP
(
int fSystemExit
)
{
// Avoid warnings on unused (but required) formal parameters
fSystemExit = fSystemExit;
return 1;
}
LIBRARY DIFFNAME
DESCRIPTION 'Sample DLL where LIBRARY name != filename'
EXETYPE WINDOWS
CODE PRELOAD MOVEABLE DISCARDABLE
DATA PRELOAD SINGLE MOVEABLE
EXPORTS
WEP @1 RESIDENTNAME
TEST @2
CL /c /ASw /W3 TEST.C
LINK /NOE /NOD TEST.OBJ+LIBENTRY.OBJ,TEST.DLL,,LIBW+SDLLCEW,TEST.DEF;
Declare Sub Test Lib "TEST.DLL" ()
Sub Form_Load ()
Call TEST
End Sub
Additional query words: 2.00 3.00
Keywords :
Version :
Platform :
Issue type :
Last Reviewed: June 1, 1999