📄 pgvbdll.gml
字号:
.id Add3
and
.id Add2
respectively.
The "Indirect call" button will call the 16-bit DLL, which will
then call the 32-bit DLL, for both
.id Function1
and
.id Function2.
To run the Visual Basic program, select "Start" from the "Run" menu.
.*
.section Sample Visual Basic DLL Programs
.*
.np
.ix 'Visual Basic' '16-bit DLL'
.ix 'Visual Basic' '32-bit DLL'
The sample programs provided below are for a 32-bit DLL, and a 16-bit
cover DLL, which will call the two functions contained in the 32-bit
DLL.
.*
.beglevel
.*
.section Source Code for VBDLL32.DLL
.*
.ix 'Visual Basic' '32-bit DLL'
.if '&lang' eq 'C' or '&lang' eq 'C/C++' .do begin
.code begin
/*
* VBDLL32.C
*/
#include <stdio.h>
#include <windows.h> /* required for all Windows applications */
.code break
long FAR PASCAL Add3( short var1, long varlong, short var2 )
{
char buf[128];
sprintf( buf, "Add3: var1=%d, varlong=%ld, var2=%d",
var1, varlong, var2 );
MessageBox( NULL, buf, "VBDLL32", MB_OK | MB_TASKMODAL );
return( var1 + varlong + var2 );
}
.code break
long FAR PASCAL Add2( long varlong, short var2 )
{
char buf[128];
sprintf( buf, "Add2: varlong=%ld, var2=%d", varlong, var2 );
MessageBox( NULL, buf, "VBDLL32", MB_OK | MB_TASKMODAL );
return( varlong + var2 );
}
.code break
#pragma off (unreferenced);
int PASCAL WinMain(HANDLE hInstance, HANDLE x1, LPSTR lpCmdLine, int x2)
#pragma on (unreferenced);
{
DefineDLLEntry( 1, (void *) Add3, DLL_WORD, DLL_DWORD, DLL_WORD,
DLL_ENDLIST );
DefineDLLEntry( 2, (void *) Add2, DLL_DWORD, DLL_WORD, DLL_ENDLIST );
return( 1 );
}
.code end
.do end
.if '&lang' eq 'FORTRAN 77' .do begin
.code begin
*$include winapi.fi
* VBDLL32.FOR
* Setup: set finclude=\WATCOM\src\fortran\win
* Compile and Link: wfl386 vbdll32 -explicit -d2 -bd -l=win386
* Bind: wbind vbdll32 -d -n
.code break
*$pragma aux (dll_function) Add3
integer function Add3( w1, w2, w3 )
integer w1, w2, w3
include 'windows.fi'
character*128 str
write( str, '(16hDLL 1 arguments:, 3i10, a)' ) w1, w2, w3,
& char(0)
call MessageBox( NULL, str, 'F77 VBDLL32'c, MB_OK )
Add3 = w1 + w2 + w3
end
.code break
*$pragma aux (dll_function) Add2
integer function Add2( w1, w2 )
integer w1, w2
include 'windows.fi'
character*128 str
write( str, '(16hDLL 2 arguments:, 2i10, a)' ) w1, w2, char(0)
call MessageBox( NULL, str, 'F77 VBDLL32'c, MB_OK )
Add2 = w1 + w2
end
.code break
integer*2 function FWinMain( hInstance,
& hPrevInstance,
& lpszCmdLine,
& nCmdShow )
integer*2 hInstance
integer*2 hPrevInstance
integer*4 lpszCmdLine
integer*2 nCmdShow
include 'windows.fi'
external Add3, Add2
integer rc
.code break
rc = DefineDLLEntry( 1, Add3, DLL_DWORD, DLL_DWORD, DLL_DWORD,
& DLL_ENDLIST )
if( rc .ne. 0 )then
FWinMain = 0
return
end if
.code break
rc = DefineDLLEntry( 2, Add2, DLL_DWORD, DLL_DWORD,
& DLL_ENDLIST )
if( rc .ne. 0 )then
FWinMain = 0
return
end if
.code break
call MessageBox( NULL, '32-bit DLL started'c,
& 'F77 VBDLL32'c, MB_OK )
FWinMain = 1
end
.code end
.do end
.*
.section Source code for COVER16.DLL
.*
.np
.ix 'Visual Basic' '16-bit DLL'
The functions in this 16-bit DLL will call the functions in the 32-bit
DLL,
.fi VBDLL32.DLL,
shown above, with the appropriate
.id Win386LibEntry
call for each function.
.if '&lang' eq 'C' or '&lang' eq 'C/C++' .do begin
.code begin
/*
* COVER16.C
*/
#include <stdio.h>
#include <windows.h> /* required for all Windows applications */
typedef long (FAR PASCAL *FPROC)();
FPROC DLL_1;
FPROC DLL_2;
.code break
long FAR PASCAL __export Function1( short var1,
long var2,
short var3 )
{
return( (long) DLL_1( var1, var2, var3 ) );
}
.code break
long FAR PASCAL __export Function2( long var1, short var2 )
{
return( (long) DLL_2( var1, var2 ) );
}
.code break
#pragma off (unreferenced);
BOOL FAR PASCAL LibMain( HANDLE hInstance, WORD wDataSegment,
WORD wHeapSize, LPSTR lpszCmdLine )
#pragma on (unreferenced);
{
HANDLE hlib;
/* Do our DLL initialization */
hlib = LoadLibrary( "vbdll32.dll" );
if( hlib < 32 ) {
MessageBox( NULL,
"Make sure your PATH contains VBDLL32.DLL",
"COVER16", MB_OK | MB_ICONEXCLAMATION );
return( FALSE );
}
DLL_1 = (FPROC) GetProcAddress( hlib, "DLL1" );
DLL_2 = (FPROC) GetProcAddress( hlib, "DLL2" );
return( TRUE );
}
.code end
.do end
.if '&lang' eq 'FORTRAN 77' .do begin
.code begin
/*
* COVER16.C
*/
#include <stdio.h>
#include <windows.h> /* required for all Windows applications */
typedef long (FAR PASCAL *FPROC)();
FPROC DLL_1;
FPROC DLL_2;
.code break
long FAR PASCAL __export Function1( long var1,
long var2,
long var3 )
{
return( (long) DLL_1( var1, var2, var3 ) );
}
.code break
long FAR PASCAL __export Function2( long var1, long var2 )
{
return( (long) DLL_2( var1, var2 ) );
}
.code break
#pragma off (unreferenced);
BOOL FAR PASCAL LibMain( HANDLE hInstance, WORD wDataSegment,
WORD wHeapSize, LPSTR lpszCmdLine )
#pragma on (unreferenced);
{
HANDLE hlib;
/* Do our DLL initialization */
hlib = LoadLibrary( "vbdll32.dll" );
if( hlib < 32 ) {
MessageBox( NULL,
"Make sure your PATH contains VBDLL32.DLL",
"COVER16", MB_OK | MB_ICONEXCLAMATION );
return( FALSE );
}
DLL_1 = (FPROC) GetProcAddress( hlib, "DLL1" );
DLL_2 = (FPROC) GetProcAddress( hlib, "DLL2" );
return( TRUE );
}
.code end
.do end
.*
.endlevel
.*
.section Compiling and Linking the Examples
.*
.np
.ix 'Visual Basic' 'building examples'
To create the 32-bit DLL
.fi VBDLL32.DLL,
type the following at the command line (make sure that
.fi VBDLL32&cxt
is in your current directory):
.millust begin
.if '&lang' eq 'C' or '&lang' eq 'C/C++' .do begin
wcl386 vbdll32 -bt=windows -bd -d2 -l=win386
wbind vbdll32 -d -n
.do end
.if '&lang' eq 'FORTRAN 77' .do begin
set finclude=c:\watcom\src\fortran\win
wfl386 vbdll32 -explicit -bd -d2 -l=win386
wbind vbdll32 -d -n
.do end
.millust end
.np
To create the 16-bit DLL
.fi COVER16.DLL,
type the following at the command line (make sure that
.fi COVER16.C
are in your current directory):
.millust begin
wcl cover16 -mc -bt=windows -bd -zu -d2 -l=windows_dll
.millust end
.autonote Notes:
.if '&lang' eq 'FORTRAN 77' .do begin
.note
An object file is provided for
.fi COVER16.C
if you do not have access to the 16-bit &company C compiler.
In this case, the DLL can be generated from the object file using
the following command:
.millust begin
wfl cover16.obj -d2 -l=windows_dll
.millust end
.do end
.note
The "mc" option selects the compact memory model (small code, big
data). The code for 16-bit DLLs must be compiled with one of the big
data models.
.note
The "bd" option indicates that a DLL will be created from the object
files.
.note
The "bt" option selects the "windows" target. This option causes the C
or C++ compiler to generate Windows prologue/epilogue code sequences
which are required for Microsoft Windows applications. It also causes
the compiler to use the
.ev WINDOWS_INCLUDE
environment variable for header file searches.
It also causes the compiler to define the macro
.kwm __WINDOWS__
and, for the 32-bit C or C++ compiler only, the macro
.kwm __WINDOWS_386__.
.note
The "zu" option is used when compiling 16-bit code that is to be placed
in a Dynamic Link Library (DLL) since the SS register points to the
stack segment of the calling application upon entry to the function.
.note
The "d2" option is used to disable optimizations and include debugging
information in the object file and DLL.
The techniques for debugging DLLs are described in the chapter
entitled :HDREF refid='wdll32'..
.endnote
.np
You are now ready to run the Visual Basic application.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -