Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
0)
Wednesday, December 9, 1998, 8:06AM
These are the original notes distributed with the 3.2.50 version of
Demo1. In the transition from 16bit to 32bit these programs have been
successfully executed with Visual Object COBOL, Workbench 4.0,
NetExpress 1.0 and 2.0. There were a few minor changes made to the
source to get things to work correctly in the process. It is a future
intention to restore the source code to the original developed with
3.2.50.
Using the contents of the Zip file
---------------------------------Mixed Language Programming isn't always as "slick" as Off Loading. Some
compromises must be accepted to be successful. How to proceed.
1) Start a NetExpress Command Line.
2) Create an empty directory.
3) Change into the empty directory.
4) Unzip the VB5D1NX3.ZIP file into the new directory.
5) Execute DOIT.BAT to compile and link the COBOL programs.
6) Type DEMO1.EXE<Enter> to execute the example. The Visual Basic Run
time files are included so the example should execute even if Visual
Basic hasn't been installed. Click the various buttons in the example
until you get bored with it. Then Click the Quit button to terminate
the example. The various Message Box displays you'll see show
information about the parameters being received and returned by the
COBOL programs and progress through the Dlls for the file handling
buttons.
7) Go to the Windows Desktop (don't close the NetExpress Command Line).
Using Find, determine the drive and path to where your Visual Basic 5
executable (VB5.EXE) is located (drive:\path\VB5.EXE).
8) Return to the NetExpress Command Line (back to where we were in step
six). Type drive:\path\VB5.EXE<Enter>. This should start Visual Basic.
Open the Demo1 project and Debug the Visual Basic application. This
will provide you an opportunity to view the comments in the Visual
Basic code and see the Message Boxes from the COBOL programs, again.
9) When you tire of Visual Basic, terminate it and from the Command
line type Mfnetx.exe<Enter>. This will start NetExpress within this
directory. Create a New Project named Demo1. Start by populating the
project with Demo1.exe, Msvbvm50.dll and Oleaut32.dll. Then add
Coboldll.cbl to the project, selecting object code and packaging as a
Dll. All the Dlls should be packaged this way. The Build settings for
this Dll need to be custumized to keep the temporary linker files.
Select the Advanced Category on the Link Tab in Build Settings and
check the Check box fo Keep temporary link files. Next add Coboldl2 to
the project. This Dll requires a graphical setting. You'll need to add
a -g switch setting to the Cbllink Directives on the Link tab in the
Advanced Category. Next add Coboldl3 and Coboldl4. Both of these Dlls
need the Include System Files check box unchecked. This check box is on
the Link Tab in Build settings, Category Advanced. They also need
access to the Coboldll.lib file. This is also on the Link Tab, Advanced
Category. Just type the library name, preceded by the drive:\path where
the Lib file is located, into the text window. The remaining Dlls,
Coboldl5, Coboldl6 and Coboldl7 do not require any special settings.
Now that everything is setup, you can do a Rebuild All from the Project
Menu. What should be the result of the Rebuild All is that all the
Cobol Dlls and the Visual Basic programs end up in the Debug directory.
You can confirm this by openning the original prompt from your TaskBar
(never hide the TaskBar, it is just too handy to have hidden). What's
definitely going to be missing is the data file, which is an indexed
file, so either manually copy these files (Idxfile.dat, Idxfile.idx)
into the Debug directory. If you don't copy these files, you will find
out what happens when the files are missing. (You can do both, try one
of the file handling buttons with no files, then copy them over, and
try it again.) (Now, right mouse Click on Demo1.exe and Click Animate.
Click Browse, and see if there is a Debug directory visible. If there
is, open this directory and select Demo1.exe. The VB Application should
start and when you click on one of the buttons the Animator should show
you the source for the Cobol programs. While you are Animating the
Cobol programs you can read the comments, but more importantly you can
examine the parameters coming from Visual Basic in the linkage section.
All this is pretty neat, but remember, this Application has already
been debugged. When errors occur debugging a program that is wrong,
expect to have to Reboot, on occasion.
10) There is one last Rabbit to pull out of the hat. This one is not
recommended for the feint of heart, and will definitely recquire a
reboot when things get a little confused. Additional preparatory file
copying is needed. The Visual Basic Application files (Initial.frm,
Initial.frx, Vbcobol.bas, Demo1.mak, Demo1.vbw) need to be copied into
the Debug directory. Right mouse Click on Demo1.exe. Get into the Debug
directory and select Demo1.exe as before. When you are looking at the
"Start Animating" dialog, highlight drive:\path\Demo1.exe, and type
drive:\path\VB5.EXE in it's place. Visual Basic should come up and you
can load the project and start debugging. When a call is made to a
Cobol program, the Animator will come up and show you the Cobol
program. You will need an uncluttered TaskBar for this as the programs
involved don't always bring themselves to the front. Also, Demo1 will
work because it has been through this process. Your program, on the
other hand, being it's usual mess, isn't likely to behave quite so
well. Expect the need for Reboots. Also, turn off the CD-Rom music and
anything else that you might have running. You need all the resources
and patience available to make this go smoothly. Good Luck!
A few words about the Batch files. Createnv.bat is an example Batch
file for setting up the SDK environment and then setting the NetExpress
environment. It isn't going to work anywhere but on my machine. Just
note that there is a Batch file that comes with the SDK and it will set
up the environment variables needed. Also note that there is a program
you can run in the NetExpress Bin directory that will set up a Batch
file you can run that will inherit whet is set up for the SDK. End of
story.
Doit.bat is the Batch file used to compile and link the Cobol programs
in this example. Make note of the switches used. There is only one
graphic program in this example. It's the program that calls
MessageBox. Also note that two Dlls require the -s switch to keep the
file handler out of these programs. The file handler is in Coboldll.dll
and you don't want multiple copies of the file handler in your
application. An alternative to this approach would be to keep the file
handler out of all the Dlls, and make Mffh.dll available. That's it.
Friday, March 28, 1997, 9:11AM
Only run this example under 16bit Windows. Use VB3D132B.ZIP if you want
to
run this example under 32bit Windows.
10/13/96 3:05PM Micro Focus 3.2.50 and Visual Basic 3.0 Professional
Only run this example using Micro Focus V3.2.50. Earlier Update levels
do not
fully support this example.
Demo1 addresses Interfacing Visual Basic and COBOL. As such it only
illustrates technical details.
The Files
--------It takes a lot of files to bake this particular cake. I have grouped
them
into categories that, hopefully, are meaningful.
The Visual Basic Files
---------------------I'm not a sophisticated Visual Basic Programmer, so don't look for
anything
very fancy here.
DEMO1.MAK
- The Project Make FIle for Demo1
INITIALF.FRM - The Initial (and only) Form for Demo1
VBCOBOL.BAS - The Global Declarations for Demo1
The COBOL Files
--------------Three very helpful Micro Focus extensions were used in the creation of
Demo1, External Programs, TYPEDEFs and Level 78 items. An External
Program provides the compiler with specification details that permit
the verification of each call statement parameter picture and usage,
determines whether parameters are passed by value or reference and sets
the call convention. TYPEDEFs permit specification of data items and
records in your program consistent with items and structures defined in
a Visual Basic program or a 'C' header file. Level 78 items permit the
definition of constant values that can then be referenced symbolically.
The Language Reference Manual, Issue 14, documents External Programs on
page 4-3, TYPEDEFs on page 4-140 and Level 78 items on page 4-97.
Use copy statements to submit External Programs to the compiler. Their
symbol definitions will be stored by the compiler, the programs will
not be compiled. Your program must follow the copy statements for any
External Programs you are using and begin with an Identification
Division header, distinguishing it from the External Programs. It will
be compiled using the stored symbols and any symbols defined in your
program. CALLCONV and VBTYPES are rather simple External Programs,
serving specific objectives. The MSGBOX External Program is a complete
example.
CALLCONV.EXT MSGBOX.EXT
MessageBox Api
VBTYPES.EXT COBOLDLL.CBL COBOLDL2.CBL COBOLDL3.CBL COBOLDL4.CBL COBOLDL5.CBL COBOLDL6.CBL TEST.CBL
-
Data Files
---------These are very simple files, created and tested with the Animator. This
makes it possible to perfect the select and FD statements independent
of the program(s) that need them. These statements are good candidates
for a copy book since they may be replicated many times in different
programs. I haven't done this as the definitions are simple and I
wanted to keep the example programs complete for reading ease.
IDXFILE.DAT
IDXFILE.IDX
DLL Files
--------The following describes each of the entry points within each DLL. The
focus is on the processing accomplished.
The call
of
is most
and
COBOLDLL
-------Each COBOL DLL's initial entry point (ordinal 1) begins after the
Procedure Division header. Other examples use this entry point, but not
this one. "Just in Case," I've coded an exit program statement after
the Procedure Division header. If this entry point gets called by
accident, I don't want to "fall" into the GETINTSB routine. For further
insurance I've coded a stop run statement. I suppose this is a matter
of style more than anything else, but these statements make it clear to
me that nothing happens if you call this DLL by name.
GETINTSB
-------The GETINTSB entry point shows you how to code a COBOL program that you
want to call from Visual Basic as a subroutine. Two Integers are passed
to COBOL from Visual Basic by reference. The entry point updates the
variables and returns control to Visual Basic.
A Visual Basic Subroutine call is coded in a style a COBOL programmer
should find familiar:
Call GETINTSB(p1, p2) ... .
Small differences, but a similar overall structure. The subroutine name
isn't a non numeric literal, parameters are grouped by parenthesis
instead of a using clause, and a comma must separate adjacent
parameters.
The Visual Basic Declare statement for the call provides the details,
by
reference, by value and data types:
Declare Sub GETINTSB Lib "coboldll" (p1 As Integer, p2 As
Integer) ... .
Visual Basic's default is to pass items by reference, the same as
COBOL.
COBOL's entry statement matches Visual Basic's Declare statement in
terms of the number and position of parameters:
entry 'GETINTSB' Pascal using p1, p2. ... .
Calling convention can be omitted if coded as part of the Procedure
Division header, in which case it applies to every entry statement.
Commas separating parameters is optional in COBOL. A subroutine returns
no value.
FDLINTFN
-------The FDLINTFN entry point shows you how to code a COBOL program that you
novel about Currency items. (Most likely, you will picture edit your
numeric
items in COBOL and return the edited value to Visual Basic as a
String.)
FDLSTRFN
-------Two parameters are passed to this function, an Integer passed by value,
and a String passed by reference. An odd aspect of the String item
requires you to specify ByVal in the Declare for the Function to get a
far pointer.
Declare Function FDLSTRFN Lib "coboldll.dll" (ByVal p1 As Integer,
ByVal
p2 As String) As Integer
The declaration specifies that the String variable is passed by value.
A far pointer to the location of the String in Visual Basic's memory is
what gets passed. The actual String value is a null terminated series
of characters.
To ensure that the your program doesn't overlay the null character, or
spoil an adjacent area of unknown content, pass the current length of a
String as a separate item. Visual Basic needs the null to manipulate
the String. The Len (length) operator always reflects the current
length of a String variable.
FXLNSTRF
-------This Function receives two parameters, an Integer, and a Fixed Length
String. Again, this is a little odd. The Declare specifies ByVal (by
value) for both items.
Declare Function FXLNSTRF Lib "coboldll.dll" (ByVal p1 As Integer,
ByVal
p2 As String) As Integer
The Fixed Length String must be defined as such.
Global p2 As String * 5
The result is the same as in FDLSTRFN, a far pointer to the String
item. The actual String value is a null terminated series of
characters.
Just as with the variable length String, passing the length may be
useful. Unlike a variable length String, a Fixed Length String's length
is constant, regardless of how many non space characters make up the
current value.
Note: Perhaps I didn't read the MS Documentation correctly. I believed
this couldn't be done. I found two independent sources that said it
could, so I've included an example. Perhaps MS meant that if you pass a
fixed length String by value, what is received is a far pointer to a
null terminated String.
CBLDLLEP
-------This is a subroutine. No parameters are passed. It demonstrates basic
file processing, Open the file, access a record, close the file and
return. You must close the file before returning to Visual Basic.
Failure to close the file will cause a subsequent call to the program
to fail. It will also keep the file locked so that it cannot be
have a handle handy (Hah), you can use a null (0). Text is the data you
want to display. It is a null terminated string. If the data you want
to display is numeric and a non display usage, move the data to an
edited numeric field terminated with a null. Title is what will appear
in the Title Bar of your MessageBox popup. It is also a null terminated
string. Style determines what buttons your popup will have, a null
value will get you an OK button. The value shown will get you that
lower case "i" in a blue circle, which stands for "information," and an
OK button. Return is an integer and is the return value for the
MessageBox. You can test Return to see if it worked, but then you'll
probably see the MessageBox anyway, so I don't know how valuable the
test might be. The above is included for those who are not quite ready
for
External Programs.
<s>DL3+XFH.CBLDL3EP<s>DL2.CBLDL2EP
VB<>DL4+XFH.COBOLDL4<s>DL2.CBLDL2EP
VB<>DL5.COBOLDL5<s>DL2.CBLDL2EP
<d>DL6.COBOLDL6
<d>DL6.CBLDL6EP<s>DL3+XFH.CBLDL3EP<s>DL2.CBLDL2EP
cancel COBOLDL6
Call Type Definitions
--------------------A COBOL DLL can be called dynamic.
A COBOL DLL called dynamic must be canceled by the program making the
call.
Entry points in dynamically called COBOL DLLs must also be called
dynamic.
Do not cancel entry points.
A COBOL DLL can be called static.
Do not cancel a COBOL DLL called static.
Entry points in static called COBOL DLL must also be called static.
Do not cancel entry points.
EXTFH, if required in any part of the application, must be linked into
the first COBOL DLL called from Visual Basic.
EXTFH must be linked into every DLL requiring its file handling
support.
You cannot cancel a DLL containing EXTFH.
You must call static a DLL containing EXTFH.
Call Type Table
--------------EXTFH Linked? - DLL Call Type - Entry Point Call Type - Cancel DLL?
No
static
static
No
No
dynamic
dynamic
Yes
Yes
static
static
No