⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 pgwdll32.gml

📁 开放源码的编译器open watcom 1.6.0版的源代码
💻 GML
📖 第 1 页 / 共 3 页
字号:
.code break
      dll_1 = GetProcAddress( hlib, 'DLL1'c )
      dll_2 = GetProcAddress( hlib, 'DLL2'c )

.code break
      cb = _Call16( dll_1, 'p'c, loc(args_1) )
      write( str, '(15hDLL 1 returned , i10, a)' ) args_1.sum,
     &                                             char(0)
      call MessageBox( NULL, str, 'Gen32 Test 1'c, MB_OK )

.code break
      cb = _Call16( dll_2, 'p'c, loc(args_2) )
      write( str, '(15hDLL 2 returned , f10.2, a)' ) args_2.sum,
     &                                               char(0)
      call MessageBox( NULL, str, 'Gen32 Test 2'c, MB_OK )

      FWinMain = 0

      end
.code end
.do end
.*
.if '&lang' eq 'C' or '&lang' eq 'C/C++' .do begin
.*
.section Writing a 16-bit Cover for the 32-bit DLL
.*
.np
.ix 'DLL' '16-bit cover'
The following is a suggested way to make a 32-bit DLL behave just like
a 16-bit DLL from the point of view of the person trying to use the
DLL.
.np
Create a library of cover functions for each of the entry points.
Each library entry would call the 32-bit DLL using the appropriate
index number.
.np
For example, assume we have 3 functions in our DLL,
.id Initialize,
.id DoStuff,
and
.id Finish.
Assume
.id Initialize
takes an integer,
.id DoStuff
takes an integer and a pointer, and
.id Finish
takes nothing.
We could build a 16-bit library as follows:
.exam begin
#include <windows.h>
typedef long (FAR PASCAL *FPROC)();
extern long FAR PASCAL Win386LibEntry();
FPROC LibEntry = Win386LibEntry;
.exam break
BOOL Initialize( int parm )
{
    return( LibEntry( parm, 1 ) );
}
.exam break
int DoStuff( int parm1, LPVOID parm2 )
{
    return( LibEntry( parm1, parm2, 2 ) );
}
.exam break
void Finish( void )
{
    LibEntry( 3 );
}
.exam end
.do end
.*
.section *refid=dlcreat Creating and Debugging Dynamic Link Libraries
.*
.np
.ix 'DLL' 'creating'
.ix 'DLL' 'debugging'
In the following sections, we will take you through the steps of
compiling, linking, and debugging
.if '&lang' eq 'C' or '&lang' eq 'C/C++' .do begin
both 16-bit and
.do end
32-bit Dynamic Link Libraries (DLLs).
.np
We will use example programs that are provided in source-code form in
the &cmpname package.
The files described in this chapter are located in the directory
.fi &srcdir..
The following files are provided:
.if '&lang' eq 'C' or '&lang' eq 'C/C++' .do begin
:set symbol="gen16"     value="gen16".
:set symbol="gen16u"    value="GEN16".
:set symbol="gen32"     value="gen32".
:set symbol="gen32u"    value="GEN32".
.begnote $setptnt 15
.note GEN16.&langsuffup
is the source code for a generic 16-bit Windows application that calls
functions in a 32-bit Windows DLL.
.note GEN16.LNK
is the linker directive file for linking the 16-bit Windows application.
.note GEN32.&langsuffup
is the source code for a generic 32-bit Windows application that calls
functions in both 16-bit and 32-bit Windows DLLs.
.note GEN32.LNK
is the linker directive file for linking the 32-bit Windows application.
.note DLL16.&langsuffup
is the source code for a simple 16-bit DLL containing one library
routine.
.note DLL16.LNK
is the linker directive file for linking the 16-bit Windows DLL.
.note DLL32.&langsuffup
is the source code for a more complex 32-bit DLL containing three
library routines.
.note DLL32.LNK
is the linker directive file for linking the 32-bit Windows DLL.
.note EXE16.&langsuffup
is the source code for a generic 16-bit Windows application that calls
functions in both 16-bit and 32-bit Windows DLLs.
.note DLL.&langsuffup
is the source code for a DLL containing three library routines.
The source code for this DLL can be used to create both 16-bit and
32-bit DLLs.
.note MAKEFILE
is a makefile for compiling and linking the programs described above.
.endnote
.do end
.if '&lang' eq 'FORTRAN 77' .do begin
:set symbol="gen16"     value="gen16v".
:set symbol="gen16u"    value="GEN16V".
:set symbol="gen32"     value="gen32v".
:set symbol="gen32u"    value="GEN32V".
.begnote $setptnt 15
.note WINDLLV.&langsuffup
is the source code for a simple 32-bit DLL containing two library
routines that use integer arguments to pass information.
.note GEN16V.&langsuffup
is the source code for a generic 16-bit Windows application that calls
functions in the "WINDLLV" 32-bit Windows DLL.
.note GEN32V.&langsuffup
is the source code for a generic 32-bit Windows application that calls
functions in the "WINDLLV" 32-bit Windows DLL.
.note WINDLL.&langsuffup
is the source code for a simple 32-bit DLL containing two library
routines that use structures to pass information.
.note GEN16.&langsuffup
is the source code for a generic 16-bit Windows application that calls
functions in the "WINDLL" 32-bit Windows DLL.
.note GEN32.&langsuffup
is the source code for a generic 32-bit Windows application that calls
functions in the "WINDLL" 32-bit Windows DLL.
.note MAKEFILE
is a makefile for compiling and linking the programs described above.
.endnote
.do end
.*
.beglevel
.*
.section Building the Applications
.*
.np
.ix 'DLL' 'creating'
To create the DLLs and test applications, we will use the WATCOM
&makname utility and the supplied makefile.
.if '&lang' eq 'C' or '&lang' eq 'C/C++' .do begin
.exam begin
C>wmake -f makefile
.exam end
.do end
.if '&lang' eq 'FORTRAN 77' .do begin
.exam begin
C>wmake -f makefile
.exam end
.do end
:cmt. .*
:cmt. .section Building the 16-bit Dynamic Link Library
:cmt. .*
:cmt. .np
:cmt. The following commands should be issued to create the 16-bit DLL.
:cmt. .if '&lang' eq 'C' or '&lang' eq 'C/C++' .do begin
:cmt. .exam begin
:cmt. C>&c16. dll16 /bt=windows /mc /zu /d2
:cmt. C>&lnkcmd @dll16
:cmt. .exam end
:cmt. .do end
:cmt. .if '&lang' eq 'FORTRAN 77' .do begin
:cmt. .exam begin
:cmt. C>&f16. dll16 /mc /win /zu /zc /d2
:cmt. C>&lnkcmd @dll16
:cmt. .exam end
:cmt. .do end
:cmt. .np
:cmt. We request the maximum amount of debugging information possible since
:cmt. we are going to show you, later, how to debug a 16-bit DLL.
:cmt. .do end
:cmt. .*
:cmt. .section Building the 32-bit Dynamic Link Library
:cmt. .*
:cmt. .np
:cmt. The following commands should be issued to create the 32-bit DLL.
:cmt. .ix WBIND
:cmt. .if '&lang' eq 'C' or '&lang' eq 'C/C++' .do begin
:cmt. .exam begin
:cmt. C>&c32. dll32 /bt=windows /d2
:cmt. C>&lnkcmd @dll32
:cmt. C>wbind dll32 -d -n
:cmt. .exam end
:cmt. .do end
:cmt. .if '&lang' eq 'FORTRAN 77' .do begin
:cmt. .exam begin
:cmt. C>set finclude=\WATCOM\src\fortran\win
:cmt. C>wfl386 windllv -nowarn -d2 -bd -l=win386
:cmt. C>wbind windllv -d -n
:cmt. .exam end
:cmt. .np
:cmt. The above example assumes the &cmpname package was installed in the
:cmt. "WATCOM" directory on the current disk.
:cmt. .do end
:cmt. .np
:cmt. We request the maximum amount of debugging information possible since
:cmt. we are going to show you, later, how to debug a 32-bit DLL.
:cmt. .*
:cmt. .section Building the 16-bit Generic Windows Application
:cmt. .*
:cmt. .np
:cmt. The following commands should be issued to create the 16-bit generic
:cmt. Windows application.
:cmt. .if '&lang' eq 'C' or '&lang' eq 'C/C++' .do begin
:cmt. .exam begin
:cmt. C>&c16. gen16 /bt=windows
:cmt. C>&lnkcmd. @gen16
:cmt. .exam end
:cmt. .do end
:cmt. .if '&lang' eq 'FORTRAN 77' .do begin
:cmt. .exam begin
:cmt. C>set finclude=\WATCOM\src\fortran\win
:cmt. C>wfl gen16v -nowarn -d2 -windows -l=windows
:cmt.              -"op desc '16-bit DLL Test'"
:cmt. .exam end
:cmt. .np
:cmt. The quoted option should be specified on the same line as the "wfl"
:cmt. command.
:cmt. This option is passed on to the linker.
:cmt. .do end
:cmt. .*
:cmt. .section Building the 32-bit Generic Windows Application
:cmt. .*
:cmt. .np
:cmt. The following commands should be issued to create the 32-bit generic
:cmt. Windows application.
:cmt. .ix WBIND
:cmt. .if '&lang' eq 'C' or '&lang' eq 'C/C++' .do begin
:cmt. .exam begin
:cmt. C>&c32. gen32 /bt=windows
:cmt. C>&lnkcmd @gen32
:cmt. C>wbind gen32 -n
:cmt. .exam end
:cmt. .do end
:cmt. .if '&lang' eq 'FORTRAN 77' .do begin
:cmt. .exam begin
:cmt. C>set finclude=\WATCOM\src\fortran\win
:cmt. C>wfl386 gen32v -nowarn -d2 -l=win386
:cmt. C>wbind gen32v -n -D "32-bit DLL Test"
:cmt. .exam end
:cmt. .do end
.*
.section Installing the Examples under Windows
.*
.if '&lang' eq 'C' or '&lang' eq 'C/C++' .do begin
.sr gen='exe16'
.sr genu='EXE16'
.do end
.if '&lang' eq 'FORTRAN 77' .do begin
.sr gen='gen32v'
.sr genu='GEN32v'
.do end
.np
.ix 'DLL' 'installing example'
Start up Microsoft Windows 3.x if you have not already done so.
Add the
.if '&lang' eq 'C' or '&lang' eq 'C/C++' .do begin
.fi EXE16.EXE
file
.do end
.if '&lang' eq 'FORTRAN 77' .do begin
.fi GEN16V.EXE
and
.fi GEN32V.EXE
files
.do end
to one of your Window groups using the Microsoft Program
Manager.
.autonote
.note
Select the "New..." entry from the "File" menu of the Microsoft
Windows Program Manager.
.note
Select "Program Item" from the "New Program Object" window and press
the "OK" button.
.if '&lang' eq 'C' or '&lang' eq 'C/C++' .do begin
.note
Enter "DLL Test" as a description for the EXE16 program.
Enter the full path to the EXE16 program as a command line.
.exam begin
Description:    Test
Command Line:   c:\work\dll\exe16.exe
.exam end
.do end
.if '&lang' eq 'FORTRAN 77' .do begin
.note
Enter "16-bit DLL Test" as a description for the GEN16V program.
Enter the full path to the GEN16V program as a command line.
.exam begin
Description:    16-bit DLL Test
Command Line:   c:\work\dll\gen16v.exe
.exam end
.note
Enter "32-bit DLL Test" as a description for the GEN32V program.
Enter the full path to the GEN32V program as a command line.
.exam begin
Description:    32-bit DLL Test
Command Line:   c:\work\dll\gen32v.exe
.exam end
.do end
.endnote
.if '&lang' eq 'FORTRAN 77' .do begin
.np
Use a similar procedure to install the
.fi GEN16.EXE
and
.fi GEN32.EXE
programs.
.do end
.*
.section Running the Examples
.*
.np
.ix 'DLL' 'running example'
Start the 16-bit application by double clicking on its icon.
A number of message boxes are presented.
You may wish to compare the output in each message box with the source
code of the program to determine if the correct results are being
obtained.
Click on the "OK" button as each of them are displayed.
.if '&lang' eq 'FORTRAN 77' .do begin
.np
Similarly, start the 32-bit application by double-clicking on its
icon and observe the results.
.do end
.*
.section Debugging a 32-bit DLL
.*
.np
.ix 'DLL' 'debugging example'
The &dbgname can be used to debug a DLL.
To debug a 32-bit DLL, a "breakpoint" instruction must be inserted
into the source code for the DLL at the "&winmain." entry point.
This is done using the "pragma" compiler directive.
We have already added the breakpoint to the source code for the 32-bit
DLL.
.if '&lang' eq 'C' or '&lang' eq 'C/C++' .do begin
.exam begin
extern void BreakPoint( void );
#pragma aux BreakPoint = 0xcc;

int PASCAL WinMain( HANDLE hInstance,
                    HANDLE x1,
                    LPSTR lpCmdLine,
                    int x2 )
{
.exam break
  BreakPoint();
  DefineDLLEntry( 1, (void *) Lib1,
                        DLL_WORD,
                        DLL_DWORD,
                        DLL_WORD,
                .
                .
                .
.exam end
.do end
.if '&lang' eq 'FORTRAN 77' .do begin
.code begin
                .
                .
                .
        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
        call BreakPoint
        rc = DefineDLLEntry( 1, Add3, DLL_DWORD, DLL_DWORD, DLL_DWORD,
     &                          DLL_ENDLIST )
        if( rc .ne. 0 )then
            FWinMain = 0
            return
        end if
                .
                .
                .
.code end
.pc
The pragma for "BreakPoint" is defined in the "WINAPI.FI" file.
.do end
.np
Start up Microsoft Windows 3.x if you have not already done so.
Start the debugger by double-clicking on the &dbgname icon.
At the prompt, enter the path specification for the application.
When the debugger has successfully loaded &genu., start execution of
the program.
When the breakpoint is encountered in the 32-bit DLL, the debugger is
re-entered.
The debugger will automatically skip past the breakpoint.
.np
From this point on, you can symbolically debug the 32-bit DLL.
You might, for example, set breakpoints at the start of each DLL
routine to debug each of them as they are called.
.*
.section Summary
.*
.np
.ix 'DLL' 'summary'
Note that the "&winmain." entry point is only called once, at the
start of any application requesting it.
After this, the "&winmain." entry point is no longer called.
You may have to restart Windows to debug this section of code a second
or third time.
.*
.endlevel

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -