Integrating with External Systems Release 3.5 of Forte™ 4GL
Sun Microsystems, Inc., 901 San Antonio Road, Palo Alto, CA 94303 U.S.A. 1-800-786-7638
Part No. 806-6672-01 October 2000, Revision A Copyright 2000 Sun Microsystems, Inc., 901 San Antonio Road, Palo Alto, California 94303, U.S.A. All rights reserved. Sun Microsystems, Inc. has intellectual property rights relating to technology embodied in this product. In particular, and without limitation, these intellectual property rights include U.S. Patent 5,457,797 and may include one or more additional patents or pending patent applications in the U.S. or other countries. This product is distributed under licenses restricting its use, copying, distribution, and decompilation. No part of this product may be reproduced in any form by any means without prior written authorization of Sun and its licensors, if any. Third-party software, including font technology, is copyrighted and licensed from Sun suppliers. c-tree Plus is licensed from, and is a trademark of, FairCom Corporation. Xprinter and HyperHelp Viewer are licensed from Bristol Technology, Inc. Regents of the University of California. All SPARC trademarks are used under license and are trademarks or registered trademarks of SPARC International, Inc. in the U.S. and other countries. Products bearing SPARC trademarks are based upon an architecture developed by Sun Microsystems, Inc. UNIX is a registered trademark in the U.S. and other countries, exclusively licensed through X/Open Company, Ltd. Sun, Sun Microsystems, the Sun Logo, Forte, and Forte Fusion are trademarks or registered trademarks of Sun Microsystems, Inc. in the U.S. and other countries. Federal Acquisitions: Commercial Software — Government Users Subject to Standard License Terms and Conditions. DOCUMENTATION IS PROVIDED “AS IS” AND ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE DISCLAIMED, EXCEPT TO THE EXTENT THAT SUCH DISCLAIMERS ARE HELD TO BE LEGALLY INVALID. Contents
Preface Organization of This Manual ...... 14 Conventions...... 16 Command Syntax Conventions ...... 16 TOOL Code Conventions ...... 16 The Forte Documentation Set ...... 17 Forte 4GL ...... 17 Forte Express...... 17 Forte WebEnterprise and WebEnterprise Designer ...... 17 Forte Example Programs...... 18 Viewing and Searching PDF Files ...... 19 I Integration with Microsoft Windows Applications 1 Overview About OLE, ActiveX, and DDE ...... 24 About OLE ...... 24 Object Linking and Embedding ...... 24 Using Windows Applications ...... 24 Defining Service Objects as OLE Servers ...... 24 ActiveX Controls...... 25 Terminology used in this Part ...... 25 2 Using OLE to Access Windows Applications About Using OLE to Access Windows Applications ...... 28 Using Object Linking and Embedding ...... 29 Defining an OLE Field in the Window Workshop ...... 29 Creating an OLE Field...... 30 OLEField Properties Dialog ...... 30 Linking to an OLE Object ...... 31 Embedding a Read-Only OLE Object...... 32 Embedding an Editable OLE Object ...... 32 4
Defining an OLE Field in TOOL ...... 34 OLE Menu Groups ...... 35 Using OLE Automation ...... 36 Generating TOOL Projects That Access OLE Methods...... 37 Step 1. Generate TOOL Classes for the OLE Application...... 37 Running the Olegen Utility ...... 37 Importing the Generated Project Definition .pex File ...... 38 Step 2. Write the Forte Application Using OLE Methods ...... 39 Dealing with Variant Objects ...... 40 Step 3. Partition the TOOL Application and Make a Distribution . . 42 Step 4. Install the Client Application ...... 42 Invoking Methods on OLE Interfaces Using CDispatch...... 43 Step 1. Decide Which OLE Methods to Invoke...... 43 Step 2. Include the OLE Library as a Supplier Plan...... 44 Step 3. Instantiate an Object of the CDispatch Class...... 44 Step 4. Set the ObjectReference Attribute...... 44 Step 5. Set the Parameters You Need ...... 44 Step 6. Use InvokeMethod or InvokeMethodWithResult to Invoke the OLE Method ...... 45 Step 7. Check the Results of the Method ...... 46 Step 8. Handle Any Exceptions ...... 46 Step 9. Partition the Client Application ...... 46 Step 10. Install the Forte Application ...... 46 3 Making a Forte Service Object an OLE Server About Making a Forte Service Object an OLE Server ...... 48 Examples ...... 49 Step 1. Define a Service Object in a Forte Application ...... 50 Providing an OLE Interface for a Service Object...... 50 Providing Methods to Get and Set Attributes ...... 50 Adding Wrapper Methods to a Service Object ...... 51 Defining an OLE Interface in a New Service Object ...... 51 Raising Exceptions in the TOOL Code ...... 52 Defining the ProgID for the Service Object ...... 53 Step 2. Partition the Application Containing the Service Objects . . . . . 54 Step 3. Mark a Service Object as an OLE Server ...... 55 Step 4. Make the Distribution ...... 56 Making the Distribution with Auto-Compile and Auto-Install ...... 56 Making the Distribution without Auto-Compiling ...... 58 Step 5. Compile and Link to Produce a Shared Library and Type Libraries...... 59 fcompile command...... 59 Steps for Compiling and Linking ...... 60 Step 6. Install the Executable ...... 61 Step 7. Start the Forte Partition ...... 61 Registering the Partition ...... 62 Troubleshooting the OLE Server ...... 62
Integrating with External Systems 5
Customizing Registry Entries for a Forte OLE Server ...... 63 Deleting Obsolete Entries from the Windows Registry...... 63 Modifying How a Partition Is Autostarted ...... 65 Using DCOM with Forte OLE Servers...... 66 Changing Security Settings ...... 67 Registering the Forte OLE Server on Client Machines ...... 70 Writing OLE Clients That Access a Forte Service Object...... 71 Determining the ProgID for the Service Object ...... 71 Handling Forte Exceptions ...... 72 4 Using ActiveX Controls in TOOL Applications About Using ActiveX Controls in TOOL Applications...... 74 Overview...... 74 Support for ActiveX Controls...... 74 Including ActiveX Controls in TOOL Applications ...... 75 Using ActiveX Controls as Widgets ...... 75 Using ActiveX Controls to Display Information ...... 75 Examples...... 75 Producing TOOL Classes For an ActiveX Control ...... 76 Step 1. Install the ActiveX Control on Your System...... 76 Step 2. Run the Olegen utility ...... 77 Step 3. Import the Generated Project Definition .pex File ...... 78 Developing a Forte Application that Uses ActiveX Controls ...... 79 Before You Start...... 79 Restrictions ...... 80 Overview...... 80 Step 1. Specify the Supplier Plans...... 81 Step 2. Define an ActiveXField Widget ...... 81 In the Window Workshop—Static Definition...... 81 In TOOL Code—Dynamic Definition ...... 83 Step 3. Invoke Methods and Access Properties of the Control. . . . . 84 Step 4. Handle Events Posted by the ActiveX Control ...... 85 Partitioning the TOOL Application ...... 87 Making the Distribution and Installing the Application ...... 88 Install ActiveX Controls Where Client Partitions are Installed ...... 88 Troubleshooting ...... 89 5 Using Dynamic Data Exchange About Dynamic Data Exchange ...... 92 Forte Integration with DDE...... 92 Forte’s DDE Classes...... 92 Using Methods and Events ...... 93
Contents 6
II Using External C Functions 6 Encapsulating External C Functions About Encapsulating External C Functions ...... 98 Terminology Used in Part II ...... 98 Accessing C Functions from within Forte Applications ...... 98 TOOL Statements for Defining C projects...... 99 Prepare to Wrap C Functions ...... 100 Set up the Auto-Compile Application...... 100 Can or Should the C Project Be Multithreaded?...... 100 Make Sure the Proper C++ Compiler Is Installed ...... 101 7 Making C Functions Available to Forte Applications About Making C Functions Available to Forte Applications ...... 104 Static Loading Platforms ...... 104 Examples ...... 104 Step 1. Have the Object Modules for the C Functions ...... 105 Step 2. Create the C Project Definition File ...... 105 C Project Class Restrictions...... 105 Defining a Project...... 106 begin C statement ...... 106 Service Objects ...... 106 Supplier C projects ...... 106 Example: C Project File ...... 106 Defining Properties ...... 108 Defining a Method...... 108 Step 3. Import the C Project Definition File...... 109 Step 4. Partition the C Project ...... 109 Step 5. Make the Distribution ...... 109 Making the Distribution with Auto-Compile and Auto-Install . . . . . 110 Making the Distribution without Auto-Compiling ...... 111 Step 6. Compile and Link Shared Libraries ...... 112 Step 7. Install C Project Shared Libraries ...... 114 Updating C Projects ...... 115 Making Installed C Projects Known to Other Repositories ...... 116 8 Writing TOOL Code That Uses C Functions About Writing TOOL Code That Uses C Functions ...... 118 Examples ...... 118 Step 1. Add the C Project as the Supplier Project ...... 119 Step 2. For a Distributed Application, Define a Service Object ...... 119 Step 3. Write the TOOL Application...... 120 Instantiate an Object for the C Class You Want to Use ...... 120 Use the Methods of the C Class ...... 120 Map C Function Parameters to TOOL Method Parameters ...... 120 Include Error Handling...... 120
Integrating with External Systems 7
Step 4. Test Your Application ...... 121 Troubleshooting...... 121 Unexpected Failures ...... 121 Unable to Locate the 3GL Supplier Library...... 121 Step 5. Partition Your Application ...... 121 Step 6. Deploy the Application ...... 122 9 TOOL Statements for Defining C Projects begin c ...... 124 Syntax ...... 124 Description ...... 124 Project Name ...... 124 Includes Clause ...... 124 Definition List...... 125 Has Property Clause ...... 125 restricted Property ...... 125 compatibilitylevel Property ...... 125 multithreaded Property ...... 125 libraryname property ...... 126 Extended External Properties ...... 126 class ...... 128 Syntax ...... 128 Description ...... 128 Methods ...... 128 10 Using C Data Types in TOOL Using C Data Types in TOOL Methods ...... 130 General Guidelines...... 130 Mapping Simple C Data Types to TOOL Data Types ...... 131 Mapping Derived C Data Types to TOOL Data Types ...... 133 Restrictions ...... 133 C-style Arrays ...... 134 Differences Between Array Objects and C-style Arrays ...... 134 Declaring Arrays on the Runtime Stack ...... 134 Declaring C-style Arrays Dynamically ...... 136 Converting C-style Arrays of Char to TextData Objects...... 136 Converting TextData Objects to C-style Array of Char ...... 137 Converting TOOL Strings to C-style Arrays of Char ...... 137 Enumeration Data Types (enums) ...... 138 Pointers ...... 140 Generic Pointers ...... 140 Pointers to Specific Data Types ...... 141 Dereferencing Pointers ...... 141 Address Operator (&)...... 142 Pointer Constants...... 143 Casting Pointers ...... 143
Contents 8
Struct Data Types...... 144 Accessing Values in a Data Structure ...... 145 Alignment of Structs ...... 146 Defining Structs within Structs ...... 146 Defining Opaque Structs ...... 147 Determining the Name Scope of Structs...... 149 Typedef Data Types ...... 150 Union Data Types ...... 151 Operator Precedence and Associativity ...... 153 Managing Memory for C-style Arrays and Data Structures ...... 154 Dynamically Managing Memory...... 155 calloc ...... 155 free ...... 156 malloc ...... 156 strdup ...... 156 sizeof ...... 157 Casting Pointers Returned by C Functions ...... 157 Managing Memory in Exception Handling...... 157 Managing Memory for Asynchronous Processing ...... 157 Managing Memory Using ExternalRef Subclasses ...... 158 Mapping C Function Parameters in TOOL Methods ...... 159 Mapping Simple C Data Type Parameters...... 160 Mapping Pointer Parameters...... 160 Passing an Input Value with the Pointer ...... 160 Getting an Output Value using the Pointer ...... 161 Passing an Input Value That Will Change ...... 161 Mapping Data Structure Parameters...... 161 Mapping C-Style Array Parameters ...... 162 Mapping Return Values ...... 162 Specifying TOOL Parameter Options...... 163 Input Mechanism ...... 163 Output Mechanism ...... 164 Input Output Mechanism ...... 165 III Writing C++ Client Applications 11 Accessing Forte Using C++ About Accessing Forte Using C++ ...... 170 Terminology Used in Part 3 ...... 171 Designing an Application to be Accessed by C++ ...... 172 Restrictions when Generating and Using a C++ API ...... 172 C++ API Uses Case Defined in TOOL ...... 172 No Virtual Attributes ...... 172 Cannot Use Subclasses of Display Library Classes ...... 172 No C++ API for Events...... 172 Supplier Libraries Must Be Compiled and Have Handle Classes. . . 172 Defining a Client Partition for the C++ API ...... 173
Integrating with External Systems 9
Generating a C++ API for a Forte Application...... 174 Step 1. Partition the Application ...... 174 Step 2. Set the Compiled and Client Partition Options...... 175 Step 3. Make the Distribution ...... 175 Using the Auto-compile and Auto-install Feature ...... 175 Step 4. Compile and Install (If Auto-compile and Auto-install Are Not Used)...... 176 Using the fcompile Command to Generate the C++ API...... 177 Writing a C++ Client Application That Accesses a Forte Application . . 178 Understanding the C++ API...... 178 Getting an Overview: client_component_id.txt ...... 179 Locating Global Functions: client_component_id.h ...... 180 Locating Class Definitions: c#.cdf ...... 180 Setting up Your System and Compiler to Use the C++ API ...... 181 Writing a C++ Client Application ...... 183 How to Use qqhTaskHandle...... 183 How to Use Forte Data Types ...... 183 Start Forte Interaction ...... 184 Passing Startup Parameters to Forte ...... 184 Logging Information for Forte Client Partitions ...... 185 Interacting with Service Objects ...... 185 Using Handle Classes and Methods...... 186 Interacting with the Forte Runtime System ...... 187 Shutting Down the Forte Client Partition...... 187 Handling Forte Exceptions ...... 188 Compiling the C++ Client Application ...... 189 Deploying the C++ Client Application ...... 189 Interacting with the Forte Runtime System ...... 190 Working with Forte Classes ...... 190 Working with Forte Runtime Objects...... 190 12 C++ API Reference Information Files Generated as Part of a C++ API ...... 192 client_component_id.txt ...... 192 client_component_id.h ...... 193 client_component_id.xxx (shared library) ...... 193 client_component_id.lib ...... 194 c#.cdf...... 194 p#.h ...... 194 Elements of the C++ API to a Client Application ...... 195 Handle Classes ...... 195 C++ Classes—for Type Conversion...... 196 Methods ...... 196 Attributes ...... 197 Service Objects ...... 197 Exceptions...... 197 Events ...... 199 Special Handling for Array and Pointer to Char Parameters ...... 199
Contents 10
Utility Global Functions and Member Functions...... 201 Functions that Start and Stop the Forte Runtime System ...... 201 ForteStartup Function ...... 201 ForteShutdown Function ...... 201 qqhObject Handle Class ...... 202 Delete( ) Member Function ...... 202 IsNil( ) Member Function ...... 203 New( ) Member Function ...... 203 SetObject( ) Member Function...... 203 The C++ API to the Forte Runtime System...... 204 IV Using Network and Operating System Features 13 Using System Activities and Network Connections About Using System Activities and Network Connections ...... 208 About System Activities ...... 208 About the ExternalConnection Class...... 208 Using System Activities...... 209 Supported System Activities ...... 209 Working with System Activities ...... 209 Registering for Notification about System Activities ...... 209 Waiting for Activity Completion ...... 210 When the Activity Completes...... 212 General Design Suggestions ...... 213 Available Interfaces ...... 213 Setting Up User-Defined Activities ...... 214 Using the ExternalConnection Class ...... 215 Types of Connections ...... 216 Basic Concepts ...... 216 Accepting Inbound Connections ...... 217 Making Outbound Connections ...... 219 Using MemoryStream Buffers ...... 219 Data Sharing Issues...... 220 Scaling Issues...... 221 Using Multiple Tasks for a Single Connection ...... 221 Using Task-Level Asynchronous Reads ...... 222 Error Handling ...... 223 Diagnostics for ExternalConnection ...... 224 A Forte Example Applications Overview of Forte Example Applications ...... 226 ActiveX Examples ...... 226 C...... 226 C++ ...... 226 DDE Examples ...... 226 ExternalConnection ...... 226 OLE Examples ...... 226
Integrating with External Systems 11
Application Descriptions...... 227 ActiveXDemo ...... 227 FourDir ActiveX Control...... 229 AllCType ...... 229 CPPBanking ...... 230 DDEClient ...... 231 DDEServer...... 231 DMathTm ...... 232 InboundExternalConnection ...... 233 MathTime ...... 234 OLEBankEV ...... 235 OLEBankUV ...... 236 OLESample ...... 237 OutboundExternalConnection ...... 238 XRefTime ...... 239 B Olegen Mapping Conventions Olegen Mapping Conventions ...... 242 Mapping OLE Automation Interfaces to TOOL Classes ...... 242 Mapping ActiveX Interfaces to TOOL Classes...... 242 Mapping Data Types in TOOL ...... 243 Mapping Return Values of Methods...... 244 Mapping Optional Parameters in Methods ...... 244 Mapping Names That Are Forte Reserved Words ...... 245 Mapping ActiveX Control Events to Forte Events ...... 246 Index ...... 247
Contents 12
Integrating with External Systems Preface
This manual, Integrating with External Systems, provides reference and usage information about integrating Forte applications with external products. It contains instructions for integrating and an appendix with descriptions of sample Forte applications demonstrating the concepts found in the manual. 14 Organization of This Manual
Organization of This Manual
This manual contains four parts and two appendixes:
Chapter (Sheet 1 of 2) Description
Part I, “Integration with Microsoft Windows Provides usage and reference information about Applications” on page 21 integrating Forte applications with Microsoft windows applications.
❚ Chapter 1, “Overview” Provides an overview about how Forte supports Microsoft’s OLE 2, ActiveX, and DDE on Windows platforms.
❚ Chapter 2, “Using OLE to Access Windows Explains how you can use OLE linking and embedding and Applications” OLE Automation in your Forte applications.
❚ Chapter 3, “Making a Forte Service Object an OLE Describes how to make service objects in a Forte Server” application available as OLE servers on the Windows 95 and Windows NT platforms.
❚ Chapter 4, “Using ActiveX Controls in TOOL Explains how you can use ActiveX in the graphical user Applications” interfaces of your Forte clients that are running in a Windows NT or Windows 95 environment
❚ Chapter 5, “Using Dynamic Data Exchange” Discusses how to enable Forte applications to communicate with Windows applications using Dynamic Data Exchange (DDE).
Part II, “Using External C Functions” on page 95 Provides complete information about the C data types you can define in TOOL when you are integrating with external systems. It also provides complete information about integrating with C.
❚ Chapter 6, “Encapsulating External C Functions” Discusses how to create classes whose methods are implemented with C functions, store them in a repository as C projects, and use the methods in your TOOL applications.
❚ Chapter 7, “Making C Functions Available to Forte Explains how you define a C project whose methods map Applications” to C functions.
❚ Chapter 8, “Writing TOOL Code That Uses C Explains how to include C functions in your TOOL Functions” application.
❚ Chapter 9, “TOOL Statements for Defining C Contains a reference of the TOOL statements for defining Projects” C projects.
❚ Chapter 10, “Using C Data Types in TOOL” With Forte, you can write applications that interact using several industry-standard products and protocols. This chapter explains how Forte you can use several standard C data types to pass parameters between Forte TOOL methods and certain types of external applications.
Part III, “Writing C++ Client Applications” on Provides complete information about integrating with C++. page 167
❚ Chapter 11, “Accessing Forte Using C++” Explains how you can generate a C++ API that lets you access your Forte appliation using C++ calls.
❚ Chapter 12, “C++ API Reference Information” Describes the handle classes that are generated by Forte when you have Forte generate a C++ API for a client partition.
Integrating with External Systems Organization of This Manual 15
Chapter (Sheet 2 of 2) Description
Part IV, “Using Network and Operating System Describes how you can use system activities and network Features” on page 205 sockets to enable your application to communicate with a Forte applications.
❚ Chapter 13, “Using System Activities and Network Discusses how to interact with other applications using Connections” system activities and network connections.
Appendix A, “Forte Example Applications” Provides instructions for using the example appliations used in this manual.
Appendix B, “Olegen Mapping Conventions” Describes how the Olegen utility interprets the interfaces provided by OLE servers and ActiveX controls
Preface 16 Conventions
Conventions
This manual uses standard Forte documentation conventions in specifying command syntax and in documenting TOOL code. Command Syntax Conventions
The specifications of command syntax in this manual use a “brackets and braces” format. The following table describes this format:
Format Description
bold Bold text is a reserved word; type the word exactly as shown.
italics Italicized text is a generic term that represents a set of options or values. Substitute an appropriate clause or value where you see italic text.
UPPERCASE Uppercase text represents a constant. Type uppercase text exactly as shown.
underline Underlined text represents a default value.
vertical bars | Vertical bars indicate a mutually exclusive choice between items. See braces and brackets, below.
braces { } Braces indicate a required clause. When a list of items separated by vertical bars is enclosed in braces, you must enter one of the items from the list. Do not enter the braces or vertical bars.
brackets [ ] Brackets indicate an optional clause. When a list of items separated by vertical bars is enclosed by brackets, you can either select one item from the list or ignore the entire clause. Do not enter the brackets or vertical bars.
ellipsis … The item preceding an ellipsis may be repeated one or more times. When a clause in braces is followed by an ellipsis, you can use the clause one or more times. When a clause in brackets is followed by an ellipsis, you can use the clause zero or more times.
TOOL Code Conventions
Where this manual includes documentation or examples of TOOL code, the TOOL code conventions in the following table are used.
Format Description
parentheses ( ) Parentheses are used in TOOL code to enclose a parameter list. Always include the parentheses with the parameter list.
comma , Commas are used in TOOL code to separate items in a parameter list. Always include the commas in the parameter list.
colon : Colons are used in TOOL code to separate a name from a type, or to indicate a Forte name in a SQL statement. Always include the colon in the type declaration or statement.
semicolon ; Semicolons are used in TOOL code to end a TOOL statement. Always type a semicolon at the end of a statement.
Integrating with External Systems The Forte Documentation Set 17
The Forte Documentation Set
Forte produces a comprehensive documentation set describing the libraries, languages, workshops, and utilities of the Forte Application Environment. The complete Forte Release 3 documentation set consists of the following manuals in addition to comprehensive online Help . Forte 4GL