AIP4089: BIS and COM In Action
Wed Nov 6, 1:30pm
                       COM
Discussion Outline
•   Who is SCB?
•   What Is COM?
•   BIS’s COM Client Interface
•   Writing your own COM component
•   Working with other components
•   Gotchas
•   Questions and Answers
Software Services Business


 1994        1999       2002
What do we do?
IT Consulting               IT Outsourcing                 IT Professional Staffing
Project Management          System development &           Application Development
                            Integration
IT Wellness testing                                        Database/IT project management
                            System Maintenance, support
Information strategy        and reengineering              Datacenter Operations
planning
                            Facilities Management          Mainframe/Midrange Support
IT Cost Analysis and ROI
                            Legacy System Transformation   Training (mentoring, classroom,
Internet & Legacy Systems                                  or customized)
Integration                 Migration Service
                                                           Data Warehousing
Systems Design and          Data Center Management
programming                                                PC/LAN Help Desk Support
                            Remote Processing
                                                           Network design, administration,
                                                           and operations
Solution Services Group

Business Information Server                            Internet Commerce Enabler
        (MAPPER)                                                (Cool ICE)


                              Modernization Services
COM   What is COM?
What is COM?
   COM (component object model)
   History
    •   DDE (dynamic data exchange)
    •   OLE 1.0 (object linking and embedding)
    •   VBX (VB controls, just for VB)
    •   OLE 2
    •   OCX (OLE Controls, VB, C, C++, Java)
    •   Renamed ActiveX
What is COM?
                                            COM
   A COM component
    • Has “public” interfaces (properties, methods,
      and events)
    • Has “private” variables, subroutines and
      functions
    • Reports “public” interfaces (properties,
      methods, and events)
    • Can include usage information with public
      interfaces (properties, methods, and events)
   COM info stored in Windows Registry
   Startup and persistence managed by
    Windows OS
What is COM?
   Library
    •   Package of class(es). In VB: the project.
   Class
    •   The COM component. Has code and data structure.
    •   In VB an executable can have zero or more forms,
        zero or more classes, and zero or modules
   Instance
    •   One working copy of the class
   Collection
    •   Like an array but each entry can be different
   Executable
    •   .EXE   -out-of-process server     -separate memory
    •   .DLL   -in-process server         -shares memory
What is COM?
     Comparison with DDE
Category                 DDE                        COM

Age                      Old and orphaned           Recent and evolving

Application complexity   Moderate                   Very

Relative speed           Fast                       Faster

BIS Availability         W2K, UNIX, 2200            W2K only

BIS-W2K level            4.0 or above               8.1E1 or above (ICE 3.0 or above)
Execute location         On workstation under MPC   On server under MAPPER.exe
Foreground execution     Yes                        Yes

Background execution     No                         Yes

Scheduled execution      No                         Yes

Data Types               Text only                  Text, Integer, Boolean, Array, Rid
What is COM?
   BIS / COM interface best used with:
    • Centralized e-mail server
    • Centralized fax server
    • Centralized message server:
       •
           LEMS (Law Enforcement Messaging Switch)
       •
           MQSeries (messaging middleware for
           heterogeneous hosts by IBM)
    • Centralized data transfer server
BIS’s COM Client Interface


         COM
BIS’s COM Client Interface
   BIS-NT 8.1E1 and above
    • Outbound only (@CCC)
   ICE 3.0 and above
    • Outbound (@CCC)
    • Inbound (ICE services)
   Not available on 2200 or UNIX
BIS’s COM Client Interface
   ICE 3.0 Inbound COM
   CoolSession object
     Methods
      CoolSession.Open GatewayName, UserID, Dept, Pswd
      CoolSession.Close
•   CoolServer object
     Properties
      string = CoolServer.MIMETYPE
      variant = CoolServer.ServiceOutput
     Methods
      Open      CreateDataSet      ExecuteDataService
      Close     ExecuteService     RemoveDataSet
                RetreiveDataSet    ProcessXML
BIS’s COM Client Interface
•   @CCC    -create an instance
•   @CCP    -put a property value
•   @CCG -get a property value
•   @CCI    -invoke a method
•   @CCR    -release the instance
•   Missing is an “Advise”
BIS’s COM Client Interface
   @CCC -Create instance
   @CCC,label prog-id handle vmsg .
    • prog-id      -VB:       project.class
                   -Excel:    Excel.Application
                   -Word:     Word.Application
                   -e-mail:   CDONTS.NewMail, et. al.
                   -others:   see OLE Viewer
    • handle       <handle>i2
    • vmsg         <errmsg>s

@cci,199 MAPZIP.ZipManager <mz>i2 <msg>s256
   Only five instance handles available
BIS’s COM Client Interface
   @CCP -Put property value
   @CCP[,label] hdl,property fmt value [vmsg] .
    • hdl        -instance handle from @CCC
    • property   -components property name
    • fmt        -BOOL       <var>i1
                  -BSTR          string
                  -I2            small integer
                  -I4            large integer
                  -R4            real (floating)
                  -VAR           rid or result
    • value       -literal or variable or ([c,d,]-0,delim)
    • vmsg        <errmsg>s
BIS’s COM Client Interface
   @CCP   -Put property value
@ccp,199 <mz>,Temp BSTR ‘c:pcme’ <msg>s256

@ldv <rep>i4=314 .
@ccp,199 <mz>,Repeat I2 <rep> <msg> .

@brk .
Salut mon vieux,
J’espere que tu va bien.
Ton amis toujours…
@brk ldv <lf>h1=chr$ 12 . line-feed delimiter
@ccp,199 <mz>,BodyText bstr (-0,<lf>) <msg>
BIS’s COM Client Interface
   @CCG -Get property value
   @CCG[,label] hdl,property return [vmsg] .
    • hdl        -instance handle from @CCC
    • property   -components property name
    • return     -variable of proper type and size
                    or array element or (c,d,r)
    • vmsg         <errmsg>s
BIS’s COM Client Interface
   @CCG -Get property value
@ccg,199 <mz>,Count   <files>i3 <msg>s256 .

@ccg,199 <mz>,Comment <cmt>s80   <msg>s256 .

@ccg,199 <mz>,Item(2) <ele>h18   <msg>s256 .
BIS’s COM Client Interface
   @CCI     -invoke method
   @CCI[,label] hdl,method fmts params return [vmsg] .
    •   hdl        -instance handle from @CCC
    •   property   -components method name
    •   fmts       -comma separated list of formats or ‘’
    •   params     -matching comma separated list of
                    parameters (literals or variables) or ‘’
    • return       -variable of proper type and size or ‘’
    • vmsg         <errmsg>s
BIS’s COM Client Interface
   @CCI   -invoke method
@cci,199 <prj>,Close ‘’ ‘’ ‘’ <msg>s256 .

@cci,199 <mz>,AddToZip ‘’ ‘’ <ok>i1 <msg> .

@cci <lsp>,Describe bstr,bstr,bstr,i2  .
           M,W,’6ft0’,220 ‘’ <msg> .
BIS’s COM Client Interface
   @CCR -release instance
   @CCR hdl1[,hdl2,hdl3,…] .
    • hdlx      -instance handle(s) from @CCC

@ccr <az>,<bz> .
Writing your own COM component


            COM
Writing your own COM component
Writing your own COM component
http://www.microsoft.com/com/




                  http://msdn.microsoft.com/library/default.asp
Writing your own COM component
   Choose language: VB, C++, Java
   Use Microsoft Visual Studio 6.0TM
   Plan your own properties and methods
    • Keep it simple
   Use third party components
    •   Faxing:      Faxman
    •   ZIPing:      SaxZIP
    •   Messaging:   MQSeries
    •   Others:      www.componentsource.com
                     www.programmersparadise.com
Writing your own COM component
   A simple project:         MapCalc
    • add or multiply two numbers
   Name the class:           AddMult
   Properties
    • op1    -integer
    • op2    -integer
   Methods
    • Add    -add op1 to op2 and return sum
    • Mult   -multiply op1 by op2 and return product
Writing your own COM component




     ActiveX.EXE -out-of-process server
     ActiveX.DLL -in-process server
Writing your own COM component
Option Explicit

Private mintOp1 As Integer
Private mintOp2 As Integer
-----------------------------------------------
Public Property Let Op1(ByVal vData As Integer)
    mintOp1 = vData
End Property
-----------------------------------------------
Public Property Let Op2(ByVal vData As Integer)
    mintOp2 = vData
End Property
-----------------------------------------------
Public Function Add() As Integer
    Add = mintOp1 + mintOp2
End Function
---------------------------------
Public Function Mult() As Integer
    Mult = mintOp1 * mintOp2
End Function
Writing your own COM component
   Adding a Method with parameters
   Adding a read only Property
Option Explicit

Private mintOp1 As Integer
Private mintOp2 As Integer
Private mintSum as Integer
--------------------------------------------------------------------
Public Sub AddOps (ByVal vData1 As Integer, ByVal vData2 As Integer)
    mintSum = vData1 + vData2
End Sub
--------------------------------------------------------------------
Public Property Get Sum() As Integer
    Sum = mintSum
End Property
Writing your component
   MapCalc.AddMult




                DEMO
Writing your own COM component
Writing your own COM component
   New VB project, Standard EXE, Project / References




   View / Object Browser…
    •   Shows methods
    •   Shows properties

   How?
    •   Pulled from the Registry!
Writing your own COM component
   The BIS Code (15a0)
    .DATE   01 AUG 02 15:25:25 RID     15A   01 AUG 02 JERR
    .RUN: MapCalc (COM interface to MapCalc.AddMult)
    *=======================================================
    @   ccc,99 MapCalc.AddMult <mc>i2 <msg>s256 . create

    @   ccp,98 <mc>,Op1   i2 96 <msg> .             put
    @   ccp,98 <mc>,Op2   i2 104 <msg> .            put
    @   cci,98 <mc>,Add   '' '' <sum>i8 .           invoke

    @   cci,98 <mc>,Mult ''    '' <prd>i8 .         invoke
    @   ccr <mc> .                                  release
      The sum      is <sum>.
      The product is <prd>.
    @   gto end .

    @98:ccr <mc> .                            error release
    @99:brk,0,i .
    <msg>
    @   brk dsp,-0 .                          Display error
Writing your component
   MapCalc.AddMult




                DEMO
Writing your own COM component
   Execute in RDB to see process in Task Manager




 Results
       .DATE   01 AUG 02 15:26:02      REPORT GENERATION   JERR
       *=======================================================
         The sum     is      200.
         The product is     9984.
                               ..... END REPORT .....
Writing your own COM component
   Creating an install for your component




          The install files
Working with other components


           COM
Working with other components
   Components
    • E-mail
    • Word
    • Excel
   Finding Prog-Ids
   Finding Classes, Properties, Methods
Working with other components
   “How to” and
    object models
    •   Outlook
    •   Excel
    •   Word
    •   FrontPage
    •   Project
    •   PowerPoint
    •   Access
Working with other components
   E-mail interface
    • According to
      msdn.microsoft.com/library/default.asp
    • CDONTS
      •
          Collaborative Data Objects for NT Servers
      •
          Requires Microsoft IIS or Exchange Server
      •
          Simple Object Model
    • CDO for Windows 2000
      •
          Included with the OS
      •
          More complex Object Model
Working with other components
   E-mail interface
    • CDONTS supplied with IIS and/or Exchange
Working with other components
   CDONTS.NewMail
    •   Objects
    •   Collections
    •   Methods
    •   Properties
Working with other components
   CDONTS.NewMail example
.DATE   01 AUG 02 15:25:25 RID     20A   01 AUG 02 JERR
.RUN: EZmail (COM interface to CDONTS.NewMail)
*=======================================================
@   ccc,99 CDONTS.NewMail <eml>i2 <msg>s256 .
@   ccp,98 <eml>,From    bstr ‘jmerrill2@home.com’ <msg> .

@   ccp,98 <eml>,To     bstr ‘bispeople@unite.org’ <msg>

@   ccp,98 <eml>,Subject bstr ‘COM in Action’ <msg> .

@   brk .
Salut mon vieux,
J’espere que tu va bien.
Ton amis toujours…
@   brk ldv <lf>h1=chr$ 12 .       line-feed delimiter
@   ccp,98 <eml>,BodyText bstr (-0,<lf>) <msg> .
@   cci,98 <eml>,Send ‘’ ‘’ ‘’ <msg> .
@   ccr <eml> .
                     ..... END REPORT .....
Working with other components
   Microsoft Excel
Working with other components
Excel.Application.10
*Application has Workbooks
  -add
  -open
  -close
 *Workbook has Worksheets
   -add
   -delete
   -calculate
  *Worksheet has Range
    -value (put)
    -value (get)
*Each needs a handle
*Only five available
Working with other components
    Excel.Application example
.DATE   01 AUG 02 15:25:25 RID     25A   01 AUG 02 JERR
.RUN: MapExcel (COM interface to Excel.Application.10)
*===========================================================================
@ldv <xl>i2=0,<wbs>i2=0,<wb>i2=0,<wss>i2=0,<ws>i2=0,<rng>i2=0,<nms>i2=0 .
@rer 0199 .
@ccc,0199 'Excel.Application'    <xl>   <msg>s998 .

@.
@ccg,0199 <xl>,Workbooks   <wbs>        <msg>s998 . WorkBooks collection
@ccg,0199 <wbs>,Count      <bookcnt>i2 <msg>s998 .
@cci,0199 <wbs>,Open BSTR 'c:com_adocomtest.xls' <wb> <msg>s998 . WorkBook
@ccg,0199 <wbs>,Count      <bookcnt>i2 <msg>s998 .
@.
@ccg,0199 <wb>,Worksheets <wss>         <msg>s998 . WorkSheets collection
@ccg,0199 <wss>,Count      <sheetcnt>i2 <msg>s998 .
@ccg,0199 <wss>,Item(1)    <ws>         <msg>s998 . handle to 1st WorkSheet
@.
@ccr <wbs> ldv <wbs>=0 .   release WorkBooks handle
@ccr <wss> ldv <wss>=0 .   release WorkSheets handle
@.
@ccg <ws>,Range(A1,C3)     <rng>i2      <msg>s998 . handle to Range
Working with other components
   Excel.Application example (continued)
@ccg,0199 <xl>,Names       <nms>i2      <msg>s998 . Names collection
@cci,0199 <nms>,Add BSTR,BSTR First,'=Sheet1!$A$1:$A$1' <nam>i2 <msg>
@ccr <nms> ldv <nms>=0 .                            release Names handle
@.
@ccg,0199 <nam>,RefersToRange <rng>i2   <msg>s998 . get Range handle
@ccg,0199 <rng>,Value         <cell>h18 <msg>s998 .
@ccp,0199 <rng>,Value BSTR    'Pierre' <msg>s998 .
@.
@ldv <msg>='*** OK ***' gto 0199 .
@. -------------------------------------------------------------------
@0199:if <rng> GT 0 ccr <rng> ; if <nam> GT 0 ccr <nam> ; .

@     if <nms> GT 0 ccr <nms> ; if <ws>          GT 0 ccr <ws>   ; .

@     if   <wss>   GT   0   ccr <wss> ; .
@     if   <wb>    GT   0   cci,lin1 <wb>,Close I2 1 '' <close>s998 ; .
@     if   <wb>    GT   0   ccr <wb> ; .
@     if   <wbs>   GT   0   ccr <wbs> ; if <xl> GT 0 ccr <xl> ; .

@     BRK,0,A LDV <COL>I3=1 .
<MSG>(<COL>-80)
@     INC,80 <COL> IF <MSG>(<COL>-80) NE '',(LIN-1) ; .
@     BRK DSP,-0 .
Working with other components
   Excel.Application




                  DEMO
Working with other components
   Microsoft Word
Working with other components
Word.Application
* Appl has Documents
    -add
    -open
    -close
  * Document has:
    - sections, paragraphs
    - sentences, words
* Appl has a Selection
   * Selection has Find
   * Find has:
     - target, replace
     - execute
* Each needs a handle
* Only five available
Working with other components
      Word.Application example
 .DATE   01 AUG 02 15:25:25 RID     30A   01 AUG 02 JERR
 .RUN: MapWord (COM interface to Word.Application)
 *=====================================================================
 @ldv <wrd>i2=0,<docs>i2=0,<doc>i2=0,<sel>i2=0,<fnd>i2=0,<tbl>i2=0 .
 @rer 0199 .
 @.
 @ccc,199 Word.Application    <wrd>i2 <msg>s256 .
 @ccg,199 <wrd>,Documents     <docs>i2 <msg> . Documents collection
 @cci,199 <docs>,Open BSTR 'c:com_adocomtest.doc' <doc>i2 <msg>
 @.
 @ccg,199 <wrd>,Selection     <sel>i2 <msg> . get Hdl to Selection obj
 @ccg,199 <sel>,Find          <fnd>i2 <msg> . get Hdl to Find obj
 @.
 @cci,199 <fnd>,Execute  .               (9)
          BSTR,,,,,,,,,BSTR,I2 '!org!',,,,,,,,,'Unite',2 <found>i1 .

Function Find.Execute([FindText], [MatchCase], [MatchWholeWord], [MatchWildcards],
[MatchSoundsLike], [MatchAllWordForms], [Forward], [Wrap], [Format], [ReplaceWith], [Replace],
[MatchKashida], [MatchDiacritics], [MatchAlefHamza], [MatchControl]) As Boolean
Working with other components
       Word.Application example (continued)
@cci,0199 <fnd>,Execute BSTR 'review'                 <found>i2 .
@ccp,0199 <sel>,Text    BSTR 'functional examination' <msg> .
@.
@ccr <docs> ldv <docs>=0 . release a handle

@.
@cci,199 <fnd>,Execute BSTR '!stcdtable!' <found>i1 .
@if <found> ne 0,(0070) ; ldv <lf>h1=chr$ 12 . line-feed

@cnt,0,b,2 p 'stcd' |,1 .
@ccp,199 <sel>,Text    BSTR (-0,<lf>) <msg> .
@cci,199 <sel>,ConvertToTable BSTR,,,,,,,,,,,,,I2  .
                               ‘|',,,,,,,,,,,,,1      <tbl>i2                   <msg> .
                                                   (13)
Function Selection.ConvertToTable([Separator], [NumRows], [NumColumns], [InitialColumnWidth],
[Format], [ApplyBorders], [ApplyShading], [ApplyFont], [ApplyColor], [ApplyHeadingRows],
[ApplyLastRow], [ApplyFirstColumn], [ApplyLastColumn], [AutoFit], [AutoFitBehavior],
[DefaultTableBehavior]) As Table
Working with other components
   Word.Application




                 DEMO
Working with other components
   Use DDE not COM for Excel and Word
    •   Complex object models require more than
        five handles
    •   Debugging difficult because you cannot
        make visible during execution
    •   Prone to hanging the run and requiring reboot
COM   Gotchas
Gotchas
   User-id’s and Permissions
    • Foreground = MPC script’s user-id
    • Background = MAPPERguest
    • Execute permission for C:WINNTSYSTEM32
       •
           several OLE*.DLL
    • Execute permission for the directory with
      EXE’s and DLL’s
    • Read, write, and modify permissions for
      directories accessed by component program
    • For Excel or Word: execute permissions for
      C:Program FilesMicrosoft OfficeOffice10
Gotchas
   Rudimentary Documentation
    • @CCG and @CCP offer a wealth of options
      and formats
    • How to use these options and formats is not
      explained
    • Examples using these options and formats are
      not presented
Gotchas
   Multiple Document Programs
    •   Like Excel and Word
    •   Not explained in BIS manuals
    •   No working samples from Unisys
    •   Instance handles
        •
            Need handles for many objects
        •
            Only five handles available
    • Cannot make visible for debugging
Gotchas
   Orphaned Processes
    • Monitor processes in Task Manager
    • If the run errors off without releasing the instance,
        the .EXE (or .DLL) may remain executing on the
        Task list.
        When this happens, you cannot modify the
        program or document or recompile the program.
    •   Sometimes Task Manager can end the process
    •   Sometimes you can release the process by closing
        the MPC session
    •   Sometimes you have to down and up BIS
    •   Most of the time you have to reboot the machine
Questions
         What is COM?
BIS
         BIS’s COM Client Interface
          • CCC, CCP, CCG, CCI, CCR
COM      Writing your own COM class
          • VB and ActiveX .EXE’s
         Working with other classes
YOU       • E-mail, Excel, Word
         Gotchas
For More Information, Contact:




                              2012 W. Lone Cactus Drive
                              Phoenix, AZ 85027
                              Phone: (623) 879-7900
                              Fax:    (623) 869-6984


               Web site: http://www.scb-az.com

               E-mail: info@scb.com

BIS and COM in Action

  • 1.
    AIP4089: BIS andCOM In Action Wed Nov 6, 1:30pm COM
  • 2.
    Discussion Outline • Who is SCB? • What Is COM? • BIS’s COM Client Interface • Writing your own COM component • Working with other components • Gotchas • Questions and Answers
  • 3.
  • 4.
    What do wedo? IT Consulting IT Outsourcing IT Professional Staffing Project Management System development & Application Development Integration IT Wellness testing Database/IT project management System Maintenance, support Information strategy and reengineering Datacenter Operations planning Facilities Management Mainframe/Midrange Support IT Cost Analysis and ROI Legacy System Transformation Training (mentoring, classroom, Internet & Legacy Systems or customized) Integration Migration Service Data Warehousing Systems Design and Data Center Management programming PC/LAN Help Desk Support Remote Processing Network design, administration, and operations
  • 5.
    Solution Services Group BusinessInformation Server Internet Commerce Enabler (MAPPER) (Cool ICE) Modernization Services
  • 6.
    COM What is COM?
  • 7.
    What is COM?  COM (component object model)  History • DDE (dynamic data exchange) • OLE 1.0 (object linking and embedding) • VBX (VB controls, just for VB) • OLE 2 • OCX (OLE Controls, VB, C, C++, Java) • Renamed ActiveX
  • 8.
    What is COM? COM  A COM component • Has “public” interfaces (properties, methods, and events) • Has “private” variables, subroutines and functions • Reports “public” interfaces (properties, methods, and events) • Can include usage information with public interfaces (properties, methods, and events)  COM info stored in Windows Registry  Startup and persistence managed by Windows OS
  • 9.
    What is COM?  Library • Package of class(es). In VB: the project.  Class • The COM component. Has code and data structure. • In VB an executable can have zero or more forms, zero or more classes, and zero or modules  Instance • One working copy of the class  Collection • Like an array but each entry can be different  Executable • .EXE -out-of-process server -separate memory • .DLL -in-process server -shares memory
  • 10.
    What is COM?  Comparison with DDE Category DDE COM Age Old and orphaned Recent and evolving Application complexity Moderate Very Relative speed Fast Faster BIS Availability W2K, UNIX, 2200 W2K only BIS-W2K level 4.0 or above 8.1E1 or above (ICE 3.0 or above) Execute location On workstation under MPC On server under MAPPER.exe Foreground execution Yes Yes Background execution No Yes Scheduled execution No Yes Data Types Text only Text, Integer, Boolean, Array, Rid
  • 11.
    What is COM?  BIS / COM interface best used with: • Centralized e-mail server • Centralized fax server • Centralized message server: • LEMS (Law Enforcement Messaging Switch) • MQSeries (messaging middleware for heterogeneous hosts by IBM) • Centralized data transfer server
  • 12.
    BIS’s COM ClientInterface COM
  • 13.
    BIS’s COM ClientInterface  BIS-NT 8.1E1 and above • Outbound only (@CCC)  ICE 3.0 and above • Outbound (@CCC) • Inbound (ICE services)  Not available on 2200 or UNIX
  • 14.
    BIS’s COM ClientInterface  ICE 3.0 Inbound COM  CoolSession object  Methods CoolSession.Open GatewayName, UserID, Dept, Pswd CoolSession.Close • CoolServer object  Properties string = CoolServer.MIMETYPE variant = CoolServer.ServiceOutput  Methods Open CreateDataSet ExecuteDataService Close ExecuteService RemoveDataSet RetreiveDataSet ProcessXML
  • 15.
    BIS’s COM ClientInterface • @CCC -create an instance • @CCP -put a property value • @CCG -get a property value • @CCI -invoke a method • @CCR -release the instance • Missing is an “Advise”
  • 16.
    BIS’s COM ClientInterface  @CCC -Create instance  @CCC,label prog-id handle vmsg . • prog-id -VB: project.class -Excel: Excel.Application -Word: Word.Application -e-mail: CDONTS.NewMail, et. al. -others: see OLE Viewer • handle <handle>i2 • vmsg <errmsg>s @cci,199 MAPZIP.ZipManager <mz>i2 <msg>s256  Only five instance handles available
  • 17.
    BIS’s COM ClientInterface  @CCP -Put property value  @CCP[,label] hdl,property fmt value [vmsg] . • hdl -instance handle from @CCC • property -components property name • fmt -BOOL <var>i1 -BSTR string -I2 small integer -I4 large integer -R4 real (floating) -VAR rid or result • value -literal or variable or ([c,d,]-0,delim) • vmsg <errmsg>s
  • 18.
    BIS’s COM ClientInterface  @CCP -Put property value @ccp,199 <mz>,Temp BSTR ‘c:pcme’ <msg>s256 @ldv <rep>i4=314 . @ccp,199 <mz>,Repeat I2 <rep> <msg> . @brk . Salut mon vieux, J’espere que tu va bien. Ton amis toujours… @brk ldv <lf>h1=chr$ 12 . line-feed delimiter @ccp,199 <mz>,BodyText bstr (-0,<lf>) <msg>
  • 19.
    BIS’s COM ClientInterface  @CCG -Get property value  @CCG[,label] hdl,property return [vmsg] . • hdl -instance handle from @CCC • property -components property name • return -variable of proper type and size or array element or (c,d,r) • vmsg <errmsg>s
  • 20.
    BIS’s COM ClientInterface  @CCG -Get property value @ccg,199 <mz>,Count <files>i3 <msg>s256 . @ccg,199 <mz>,Comment <cmt>s80 <msg>s256 . @ccg,199 <mz>,Item(2) <ele>h18 <msg>s256 .
  • 21.
    BIS’s COM ClientInterface  @CCI -invoke method  @CCI[,label] hdl,method fmts params return [vmsg] . • hdl -instance handle from @CCC • property -components method name • fmts -comma separated list of formats or ‘’ • params -matching comma separated list of parameters (literals or variables) or ‘’ • return -variable of proper type and size or ‘’ • vmsg <errmsg>s
  • 22.
    BIS’s COM ClientInterface  @CCI -invoke method @cci,199 <prj>,Close ‘’ ‘’ ‘’ <msg>s256 . @cci,199 <mz>,AddToZip ‘’ ‘’ <ok>i1 <msg> . @cci <lsp>,Describe bstr,bstr,bstr,i2 . M,W,’6ft0’,220 ‘’ <msg> .
  • 23.
    BIS’s COM ClientInterface  @CCR -release instance  @CCR hdl1[,hdl2,hdl3,…] . • hdlx -instance handle(s) from @CCC @ccr <az>,<bz> .
  • 24.
    Writing your ownCOM component COM
  • 25.
    Writing your ownCOM component
  • 26.
    Writing your ownCOM component http://www.microsoft.com/com/ http://msdn.microsoft.com/library/default.asp
  • 27.
    Writing your ownCOM component  Choose language: VB, C++, Java  Use Microsoft Visual Studio 6.0TM  Plan your own properties and methods • Keep it simple  Use third party components • Faxing: Faxman • ZIPing: SaxZIP • Messaging: MQSeries • Others: www.componentsource.com www.programmersparadise.com
  • 28.
    Writing your ownCOM component  A simple project: MapCalc • add or multiply two numbers  Name the class: AddMult  Properties • op1 -integer • op2 -integer  Methods • Add -add op1 to op2 and return sum • Mult -multiply op1 by op2 and return product
  • 29.
    Writing your ownCOM component  ActiveX.EXE -out-of-process server  ActiveX.DLL -in-process server
  • 30.
    Writing your ownCOM component Option Explicit Private mintOp1 As Integer Private mintOp2 As Integer ----------------------------------------------- Public Property Let Op1(ByVal vData As Integer) mintOp1 = vData End Property ----------------------------------------------- Public Property Let Op2(ByVal vData As Integer) mintOp2 = vData End Property ----------------------------------------------- Public Function Add() As Integer Add = mintOp1 + mintOp2 End Function --------------------------------- Public Function Mult() As Integer Mult = mintOp1 * mintOp2 End Function
  • 31.
    Writing your ownCOM component  Adding a Method with parameters  Adding a read only Property Option Explicit Private mintOp1 As Integer Private mintOp2 As Integer Private mintSum as Integer -------------------------------------------------------------------- Public Sub AddOps (ByVal vData1 As Integer, ByVal vData2 As Integer) mintSum = vData1 + vData2 End Sub -------------------------------------------------------------------- Public Property Get Sum() As Integer Sum = mintSum End Property
  • 32.
    Writing your component  MapCalc.AddMult DEMO
  • 33.
    Writing your ownCOM component
  • 34.
    Writing your ownCOM component  New VB project, Standard EXE, Project / References  View / Object Browser… • Shows methods • Shows properties  How? • Pulled from the Registry!
  • 35.
    Writing your ownCOM component  The BIS Code (15a0) .DATE 01 AUG 02 15:25:25 RID 15A 01 AUG 02 JERR .RUN: MapCalc (COM interface to MapCalc.AddMult) *======================================================= @ ccc,99 MapCalc.AddMult <mc>i2 <msg>s256 . create @ ccp,98 <mc>,Op1 i2 96 <msg> . put @ ccp,98 <mc>,Op2 i2 104 <msg> . put @ cci,98 <mc>,Add '' '' <sum>i8 . invoke @ cci,98 <mc>,Mult '' '' <prd>i8 . invoke @ ccr <mc> . release The sum is <sum>. The product is <prd>. @ gto end . @98:ccr <mc> . error release @99:brk,0,i . <msg> @ brk dsp,-0 . Display error
  • 36.
    Writing your component  MapCalc.AddMult DEMO
  • 37.
    Writing your ownCOM component  Execute in RDB to see process in Task Manager  Results .DATE 01 AUG 02 15:26:02 REPORT GENERATION JERR *======================================================= The sum is 200. The product is 9984. ..... END REPORT .....
  • 38.
    Writing your ownCOM component  Creating an install for your component  The install files
  • 39.
    Working with othercomponents COM
  • 40.
    Working with othercomponents  Components • E-mail • Word • Excel  Finding Prog-Ids  Finding Classes, Properties, Methods
  • 41.
    Working with othercomponents  “How to” and object models • Outlook • Excel • Word • FrontPage • Project • PowerPoint • Access
  • 42.
    Working with othercomponents  E-mail interface • According to msdn.microsoft.com/library/default.asp • CDONTS • Collaborative Data Objects for NT Servers • Requires Microsoft IIS or Exchange Server • Simple Object Model • CDO for Windows 2000 • Included with the OS • More complex Object Model
  • 43.
    Working with othercomponents  E-mail interface • CDONTS supplied with IIS and/or Exchange
  • 44.
    Working with othercomponents  CDONTS.NewMail • Objects • Collections • Methods • Properties
  • 45.
    Working with othercomponents  CDONTS.NewMail example .DATE 01 AUG 02 15:25:25 RID 20A 01 AUG 02 JERR .RUN: EZmail (COM interface to CDONTS.NewMail) *======================================================= @ ccc,99 CDONTS.NewMail <eml>i2 <msg>s256 . @ ccp,98 <eml>,From bstr ‘jmerrill2@home.com’ <msg> . @ ccp,98 <eml>,To bstr ‘bispeople@unite.org’ <msg> @ ccp,98 <eml>,Subject bstr ‘COM in Action’ <msg> . @ brk . Salut mon vieux, J’espere que tu va bien. Ton amis toujours… @ brk ldv <lf>h1=chr$ 12 . line-feed delimiter @ ccp,98 <eml>,BodyText bstr (-0,<lf>) <msg> . @ cci,98 <eml>,Send ‘’ ‘’ ‘’ <msg> . @ ccr <eml> . ..... END REPORT .....
  • 46.
    Working with othercomponents  Microsoft Excel
  • 47.
    Working with othercomponents Excel.Application.10 *Application has Workbooks -add -open -close *Workbook has Worksheets -add -delete -calculate *Worksheet has Range -value (put) -value (get) *Each needs a handle *Only five available
  • 48.
    Working with othercomponents  Excel.Application example .DATE 01 AUG 02 15:25:25 RID 25A 01 AUG 02 JERR .RUN: MapExcel (COM interface to Excel.Application.10) *=========================================================================== @ldv <xl>i2=0,<wbs>i2=0,<wb>i2=0,<wss>i2=0,<ws>i2=0,<rng>i2=0,<nms>i2=0 . @rer 0199 . @ccc,0199 'Excel.Application' <xl> <msg>s998 . @. @ccg,0199 <xl>,Workbooks <wbs> <msg>s998 . WorkBooks collection @ccg,0199 <wbs>,Count <bookcnt>i2 <msg>s998 . @cci,0199 <wbs>,Open BSTR 'c:com_adocomtest.xls' <wb> <msg>s998 . WorkBook @ccg,0199 <wbs>,Count <bookcnt>i2 <msg>s998 . @. @ccg,0199 <wb>,Worksheets <wss> <msg>s998 . WorkSheets collection @ccg,0199 <wss>,Count <sheetcnt>i2 <msg>s998 . @ccg,0199 <wss>,Item(1) <ws> <msg>s998 . handle to 1st WorkSheet @. @ccr <wbs> ldv <wbs>=0 . release WorkBooks handle @ccr <wss> ldv <wss>=0 . release WorkSheets handle @. @ccg <ws>,Range(A1,C3) <rng>i2 <msg>s998 . handle to Range
  • 49.
    Working with othercomponents  Excel.Application example (continued) @ccg,0199 <xl>,Names <nms>i2 <msg>s998 . Names collection @cci,0199 <nms>,Add BSTR,BSTR First,'=Sheet1!$A$1:$A$1' <nam>i2 <msg> @ccr <nms> ldv <nms>=0 . release Names handle @. @ccg,0199 <nam>,RefersToRange <rng>i2 <msg>s998 . get Range handle @ccg,0199 <rng>,Value <cell>h18 <msg>s998 . @ccp,0199 <rng>,Value BSTR 'Pierre' <msg>s998 . @. @ldv <msg>='*** OK ***' gto 0199 . @. ------------------------------------------------------------------- @0199:if <rng> GT 0 ccr <rng> ; if <nam> GT 0 ccr <nam> ; . @ if <nms> GT 0 ccr <nms> ; if <ws> GT 0 ccr <ws> ; . @ if <wss> GT 0 ccr <wss> ; . @ if <wb> GT 0 cci,lin1 <wb>,Close I2 1 '' <close>s998 ; . @ if <wb> GT 0 ccr <wb> ; . @ if <wbs> GT 0 ccr <wbs> ; if <xl> GT 0 ccr <xl> ; . @ BRK,0,A LDV <COL>I3=1 . <MSG>(<COL>-80) @ INC,80 <COL> IF <MSG>(<COL>-80) NE '',(LIN-1) ; . @ BRK DSP,-0 .
  • 50.
    Working with othercomponents  Excel.Application DEMO
  • 51.
    Working with othercomponents  Microsoft Word
  • 52.
    Working with othercomponents Word.Application * Appl has Documents -add -open -close * Document has: - sections, paragraphs - sentences, words * Appl has a Selection * Selection has Find * Find has: - target, replace - execute * Each needs a handle * Only five available
  • 53.
    Working with othercomponents  Word.Application example .DATE 01 AUG 02 15:25:25 RID 30A 01 AUG 02 JERR .RUN: MapWord (COM interface to Word.Application) *===================================================================== @ldv <wrd>i2=0,<docs>i2=0,<doc>i2=0,<sel>i2=0,<fnd>i2=0,<tbl>i2=0 . @rer 0199 . @. @ccc,199 Word.Application <wrd>i2 <msg>s256 . @ccg,199 <wrd>,Documents <docs>i2 <msg> . Documents collection @cci,199 <docs>,Open BSTR 'c:com_adocomtest.doc' <doc>i2 <msg> @. @ccg,199 <wrd>,Selection <sel>i2 <msg> . get Hdl to Selection obj @ccg,199 <sel>,Find <fnd>i2 <msg> . get Hdl to Find obj @. @cci,199 <fnd>,Execute . (9) BSTR,,,,,,,,,BSTR,I2 '!org!',,,,,,,,,'Unite',2 <found>i1 . Function Find.Execute([FindText], [MatchCase], [MatchWholeWord], [MatchWildcards], [MatchSoundsLike], [MatchAllWordForms], [Forward], [Wrap], [Format], [ReplaceWith], [Replace], [MatchKashida], [MatchDiacritics], [MatchAlefHamza], [MatchControl]) As Boolean
  • 54.
    Working with othercomponents  Word.Application example (continued) @cci,0199 <fnd>,Execute BSTR 'review' <found>i2 . @ccp,0199 <sel>,Text BSTR 'functional examination' <msg> . @. @ccr <docs> ldv <docs>=0 . release a handle @. @cci,199 <fnd>,Execute BSTR '!stcdtable!' <found>i1 . @if <found> ne 0,(0070) ; ldv <lf>h1=chr$ 12 . line-feed @cnt,0,b,2 p 'stcd' |,1 . @ccp,199 <sel>,Text BSTR (-0,<lf>) <msg> . @cci,199 <sel>,ConvertToTable BSTR,,,,,,,,,,,,,I2 . ‘|',,,,,,,,,,,,,1 <tbl>i2 <msg> . (13) Function Selection.ConvertToTable([Separator], [NumRows], [NumColumns], [InitialColumnWidth], [Format], [ApplyBorders], [ApplyShading], [ApplyFont], [ApplyColor], [ApplyHeadingRows], [ApplyLastRow], [ApplyFirstColumn], [ApplyLastColumn], [AutoFit], [AutoFitBehavior], [DefaultTableBehavior]) As Table
  • 55.
    Working with othercomponents  Word.Application DEMO
  • 56.
    Working with othercomponents  Use DDE not COM for Excel and Word • Complex object models require more than five handles • Debugging difficult because you cannot make visible during execution • Prone to hanging the run and requiring reboot
  • 57.
    COM Gotchas
  • 58.
    Gotchas  User-id’s and Permissions • Foreground = MPC script’s user-id • Background = MAPPERguest • Execute permission for C:WINNTSYSTEM32 • several OLE*.DLL • Execute permission for the directory with EXE’s and DLL’s • Read, write, and modify permissions for directories accessed by component program • For Excel or Word: execute permissions for C:Program FilesMicrosoft OfficeOffice10
  • 59.
    Gotchas  Rudimentary Documentation • @CCG and @CCP offer a wealth of options and formats • How to use these options and formats is not explained • Examples using these options and formats are not presented
  • 60.
    Gotchas  Multiple Document Programs • Like Excel and Word • Not explained in BIS manuals • No working samples from Unisys • Instance handles • Need handles for many objects • Only five handles available • Cannot make visible for debugging
  • 61.
    Gotchas  Orphaned Processes • Monitor processes in Task Manager • If the run errors off without releasing the instance, the .EXE (or .DLL) may remain executing on the Task list. When this happens, you cannot modify the program or document or recompile the program. • Sometimes Task Manager can end the process • Sometimes you can release the process by closing the MPC session • Sometimes you have to down and up BIS • Most of the time you have to reboot the machine
  • 62.
    Questions  What is COM? BIS  BIS’s COM Client Interface • CCC, CCP, CCG, CCI, CCR COM  Writing your own COM class • VB and ActiveX .EXE’s  Working with other classes YOU • E-mail, Excel, Word  Gotchas
  • 63.
    For More Information,Contact: 2012 W. Lone Cactus Drive Phoenix, AZ 85027 Phone: (623) 879-7900 Fax: (623) 869-6984 Web site: http://www.scb-az.com E-mail: info@scb.com

Editor's Notes

  • #2 Jerry Merrill is a Sr. Consultant with the Solutions Services Group of SCB Computer Technology. He has been working with Unisys e-@ction Business Information Server (formerly called MAPPER) since it was first marketed on 1100’s in 1980. Since then he has worked with BIS on 2200’s, MAPPER-5’s, PC’s, OS/2, Windows, NT’s, UNIX, Sun Solaris, IBM RS/6000, CTOS, A-Series, and OPUS. Mr. Merrill left Unisys in 1996 after 18 years of service, where he rose to the level of the Western Region 4GL Marketing Manager. He is the designer and developer of the methodology, tools and services used in VSS-MAP2000 and SCB-MAPPORT and M2R. He has written a dozen articles for Unisphere Magazine and is a frequent presenter at Unite conferences. Today he will present and demonstrate some real world uses of COM between BIS and Visual Basic and other applications. After this presentation, you should have all the information you need to begin building COM interfaces of your own.
  • #3 First we will find out who SCB is and what they do. Then we will examine what COM is and what it can do. After that we will review the COM interface capabilities provided by BIS and ICE. To best show how COM works we will build a COM component in Visual Basic and show you how to use it with BIS. Then we will discuss the tools that can help you work with other COM components including E-mail, Excel and Word. For each of these applications, sample code will be presented. A demo in run debug mode will also be provided. And finally we will give you a chance to ask questions.
  • #4 Vector Software Services was formed in 1994 by a number of ex-Unisys MAPPER people. The group grew and expanded rapidly. In 1999 Vector was bought out by Expanets, which operated primarily in the telecommunications arena. In April 2002 the MAPPER group left Expanets and joined SCB Computer Technology, which was more closely aligned with the products and services that they provided.
  • #5 Since 1976, SCB has been a leading provider of management and information systems consulting. The company has grown from a small partnership founded by Lyle Seltmann, Scott Cobb, and Ben Bryant, to an international, publicly traded IT consulting corporation. Initially, the firm concentrated on providing strategic planning for data processing or information technology organizations. Evolving to meet both client demands and industry trends, SCB has broadened its activities to more than just consulting services. Now, SCB offers a full array of IT management consulting and development services. With regional offices across the US, there is one close to you! SCB&apos;s reliability and reputation continue to grow, thanks to more than 800 technology professionals and lengthy client partnerships that have been an SCB hallmark since 1976.
  • #6 The Solutions Services Group of SCB specializes in products, services and support in the BIS and ICE arenas. The premier SCB-developed products in this arena are: PCME/PCMA, ICEME, VSS-RADS and ICE-RADS. They are all off-shoots of the RADS tool set. They are used for application modernization and e-business solutions. The group also offers the SCB-MAPPORT portation service and the M2R database migration service. Jerry Merrill heads up the migration services organization. The Solution Services Group also provides beginning, intermediate, and advanced training in BIS and ICE.
  • #8 COM (Component Object Model) is Microsoft’s language independent specification for interfacing programs in the Windows environment. Microsoft also provides the mechanisms for automating COM interfaces into its Windows operating systems. Microsoft started with DDE but it was not object oriented. Then they created Object Linking and Embedding which facilitated including objects in Word and Excel. Then they gave it some programming enhancements and called it just OLE. Early releases of Visual Basic provided Visual Basic Controls (VBX). Then they allowed third parties to develop VBX’s. But VBX’s had to be developed in something other than VB and worked only with VB. Then Microsoft came up with OLE controls (OCX’s). These could be written with VB (or other languages) and would work with modules written in other languages. With the rapid growth of the internet, Microsoft did some product renaming. So OCX’s became ActiveX Controls (although the executable code still has the .OCX extension). And these are the main types of “components” for COM.
  • #9 A COM component (object) encapsulates both data and code. It exposes its Public properties (variables), methods (subroutines) and events (triggers). It keeps Private and does not allow other modules to see or modify its internal variables, methods, and events. To other modules it is a black box with only its interfaces showing. The executable and published information about a COM component is stored in the Windows Registry. This means that COM components must be installed using a Microsoft provided/approved installation routine. Windows starts COM component .EXE’s or .DLL’s when an instance is created. The initiator passes Windows the component name and the OS looks up the type and location of the executable in the registry. The OS keeps track of how many processes are using a COM component. When that number returns to zero, it unloads the COM component. In some ways it operates similar to VALTAB entries and TIP programs on the 2200.
  • #10 There is a lot of new terminology involved when you start looking at building COM interfaces. A 2200 equivalent of a Library would be a Program file that contains Absolutes. A class is like a cookie cutter. And the instance is like the cookie that it actually creates. A collection is similar to an array but allows different types in its entries. Common collections are Word Documents and Excel Worksheets. Unisys says that their COM client interface will work with either EXE’s or DLL’s, but I have never been able to get it working with anything other than EXE’s. Perhaps because of how memory is allocated.
  • #11 First of all, COM is a lot newer and more widely used than DDE. While DDE is workstation oriented (it executes on the workstation thru MPC), COM is server oriented (it executes on the server under control of the MAPPER service). Another big advantage of COM is that it can run in background and can be Scheduled.
  • #12 Because the BIS COM client interface runs on the server, it is generally used for different types of things than DDE.
  • #14 Outbound COM is available both for BIS-NT 8.1E1 and above and ICE 3.0 and above. Inbound COM is only available for ICE 3.0 and above. COM interfaces are available only on Windows 2000 (or XP) servers
  • #15 The inbound COM interface, available with ICE 3.0, has two objects: CoolSession and CoolServer . We introduce the objects, methods and properties here but will not discuss them further. Refer to the ICE Developers Reference (7850 2473-002) Section 6 and Appendix B, for further details and examples.
  • #16 The commands belonging to BIS’s COM Client Interface (outbound COM) have already been discussed in Dave Yost’s presentation. But, we will be showing additional examples and perhaps a little more detail. Note that although DDE does have an “Advise” COM does not. The COM Client cannot respond to events raised in the COM components that it calls. The workaround are: have BIS loop on the @CCG of a status property and to have the COM component set the value of the status property when it is ready. invoke a method with @CCI that will not return a value until the desired task completes
  • #17 Here is an example of the @CCC statement and several of the prog-id’s used to create instances. Note that the handles are only i2. Compare that with BIS GUI statements that use i6 handles. At present, only five instance handles are available.
  • #18 Here is the syntax for the Put statement with most, but not all, of the format types.
  • #19 Here are three examples of a Put: A binary string containing a DOS directory. A small integer containing the number of times to repeat a step. A result, of type binary string, where the record separator is a line-feed. This technique could be used in most e-mail applications. If you omit the line-feed separator, only the first line will be accepted.
  • #20 Here is the format for a Get. Be sure that the return variable is of the proper size and type or the statement will error.
  • #21 Here are three examples of a Get: A small integer. A string. The second element of an array or collection.
  • #22 Here is the format of the Invoke Method. Depending on how the COM component was written you may or may not need to supply input and output parameters on the @CCI statement. Although it may be slightly less efficient, I find it easier to debug when I Put the necessary parameters before the Invoke . This greatly simplifies the Invoke . But I usually like to include a status variable in the return .
  • #23 Here are three examples of an Invoke Method: A simple close with no parameters. The command to add a file (previously Put ) into an archive (previously created) and wait for a boolean &lt;OK&gt; (0 or 1). Passing three strings and an integer to a routine that records a person’s description but provides no return status.
  • #24 Release is the simplest COM Client Interface statement. You can include from 1 to 5 instance handles per statement. Our example shows two.
  • #26 Microsoft Visual Basic 6.0 Reference Library “ The first of the three volumes in this box set, Microsoft Visual Basic 6.0 Language Reference compiles all the language features of today&apos;s Visual Basic, from basic data types and built-in control types (their methods, properties, and events) to advanced material (such as conditional compilation directives). If you&apos;ve ever had trouble remembering a string function or working with Visual Basic Variant, this first volume can help you get the right information fast.” “ The second volume, Microsoft Visual Basic 6.0 Component Tools Guide , isn&apos;t a dictionary, but an in-depth, useful tutorial to Visual Basic programming--and even to deploying ActiveX components, the technological heart of Visual Basic. After a basic tour of ActiveX controls, the text introduces each of the more than two dozen built-in ActiveX controls that ship with Visual Basic 6, from fancy widgets, such as the new DateTimePicker and Coolbar controls, to older favorites, such as the Animation and UpDown controls. “ “ Component Tools Guide looks at the considerable support for building ActiveX components--ActiveX servers (in both DLL and EXE formats), custom reusable ActiveX controls, and even ActiveX documents (suitable for use inside Internet Explorer 4). This guide discusses support for Internet applications using Dynamic HTML (DHMTL), how to connect to data sources in ActiveX controls, and how to build server-side components for Internet Information Server (IIS). You can still create &amp;quot;fat clients,&amp;quot; but this reference shows you the better way to develop with Visual Basic using ActiveX and the Internet.” “ The last volume of the set, Microsoft Visual Basic 6.0 Controls Reference , returns to reference mode with a convenient listing of the properties, events, and methods for more than two dozen standard Visual Basic controls, from user interface objects such as grids, list, and tree views to Internet transfer controls and those that provide database access. The book clearly explains each control&apos;s property, method, and event. “ Amazon.com book review
  • #27 Here are two useful COM related web sites provided Microsoft. The first is good for marketing and conceptual type information. The second is more useful to the developer.
  • #28 You can write COM components in any of several languages. The one I happen to use is Visual Basic. VB release 6.0 is included in the Microsoft Visual Studio 6.0 and contains all the pieces you need for building a COM component. First plan the properties and methods that you need to make Public in order for the component to do its job. Then you can worry about the variables, functions, subroutines and events inside the component. In many cases you can use third party components to avoid reinventing the wheel. We used FAXMAN from DataTech at Louisiana State Police. I use SAXZIP in my MAPZIP, RADS-Export, and PORT-Export routines. We will be using MQseries, a heterogeneous computer messaging middleware from IBM, at Harris County (Texas) Sheriff’s Department. www.componentsource.com and www.programmersparadise.com are both good sites for finding third party components.
  • #29 In order to demonstrate how a COM interface works, we are going to build a very elementary COM component in VB. We will call the project (our library name) MapCalc . We will name our Class AddMult . We will have two, write-only Public properties called op1 and op2 . We will have two Public methods, Add and Mult , each of which will return an integer.
  • #30 So first we are going to start VB 6.0 and create a new project. We choose Active EXE because we want an out-of-process server. A Standard EXE project is always created with a Form1 . An Active EXE project is always created with a Class1 .
  • #31 First we make sure that we name our Project “MapCalc” and our Class “AddMult”. Then we define our private variables. It is a good practice to use a different set of variables internally than you expose externally. That way other modules cannot see how you work. The “mint-” prefix on our private variables means “memory integer”. The “Public Property Let” code shows us how to code the writable portion of a property. In this code, we take whatever value ( vdata ) they send us and move it into our private variables. The “Public Function” show us how to code a method that returns a result. Both of these functions return an integer. Remember that in VB the return variable has the same name and type as the function. When we compile the project and then look at the project directory, we will see three files: .CLS -the source code of the class .EXE -the executable .VBP -the project control file
  • #32 If we did not want/need to return a result, we could use a “Public Sub”. This sub accepts two integer parameters, stores the sum in a private variable, and does not return anything. Then we could use a “Public Property Get” to make the sum readable.
  • #33 So we have to find something else that will let us specify a cell/range of cells. This is how we can do it: We get a handle to the Names collection We “Add” a “Name” and specify, in a string, the sheet and cell range to which it refers. The Add method will return a Name handle We use the “RefersToRange” of the Name to get the Range handle. Now we can GET and PUT using the Range handle. In the error handling/wrap-up section we should release any instance handle that is still open (value &gt; 0) to avoid orphan processes. We should also close any open workbooks; to keep them from remaining locked.
  • #34 One of the utilities provided with Microsoft Visual Studio 6.0 is the OLE Viewer. It reads through the registry, gathers information about COM components and presents them in a tree structure. If we start OLEVIEW.EXE, select Object Classes / All Objects, after a few moments we are presented with a list of all the COM components installed on our Windows workstation or server. We have to scroll a long way down to find MapCalc.AddMult. When we do we find the two most important things: * where the executable code is located: LocalServer32 = C:\\COM _ ADO\\Code\\MAPCALC.EXE * the value of the prog-id: ProgID = MapCalc.AddMult Registering COM Applications “ The Microsoft® Windows® registry is the system database for Windows operating systems. It contains information about the configuration of system hardware and software as well as about users of the system. Any Windows-based program can add information to the registry and read information back from the registry. Clients search the registry for interesting components to use.” “ The registry maintains information about all the COM objects installed in the system. Whenever an application creates an instance of a COM component, the registry is consulted to resolve either the CLSID or ProgID of the component into the pathname of the server DLL or EXE that contains it. After determining the component&apos;s server, Windows either loads the server into the process space of the client application (in-process components) or starts the server in its own process space (local and remote servers). The server creates an instance of the component and returns to the client a reference to one of the component&apos;s interfaces.” msdn.microsoft.com
  • #35 To determine the interfaces (properties, methods, and events) inside a COM object we can use the References facility of VB. Let’s start a new project, select Standard EXE, then do Project / References. After several moments it will pop up a list of libraries that can be included in our new project. We will scroll down and select MapCalc. Now, when we select View / Object Browser and set our Library to MapCalc and select the class AddMult, we will see a list of its Public properties and methods. How did it do this? When we compiled the project, VB added this information to the Registry. Now VB is reading and presenting what it found in the registry.
  • #36 Here is some BIS code that uses the COM component that we have just built. Let’s go thru it line by line: @CCC -create an instance of MapCalc.AddMult and save the instance handle @CCP -using the instance handle, put a value of 96 (small integer) into Op1 @CCP -using the instance handle, put a value of 104 (small integer) into Op2 @CCI -using the instance handle, invoke the Add method, which will add together Op1 and Op2 and return the sum in the &lt;SUM&gt; variable @CCI -using the instance handle, invoke the Mult method, which will multiply together Op1 and Op2 and return the product in the &lt;PRD&gt; variable @CCR -release the instance Display the result and end Error handling: @98 -since an instance has been created, we need to close it @99 -display the error message
  • #37 So we have to find something else that will let us specify a cell/range of cells. This is how we can do it: We get a handle to the Names collection We “Add” a “Name” and specify, in a string, the sheet and cell range to which it refers. The Add method will return a Name handle We use the “RefersToRange” of the Name to get the Range handle. Now we can GET and PUT using the Range handle. In the error handling/wrap-up section we should release any instance handle that is still open (value &gt; 0) to avoid orphan processes. We should also close any open workbooks; to keep them from remaining locked.
  • #38 Now let’s execute the run (15a0) in debug mode (with an RDB). As soon as we complete the @CCC, we can switch to Task Manager and see that MapCalc.exe is executing. After the @CCR executes, MapCalc.exe disappears from Task Manager. And here we have the results of our first BIS / COM interface!
  • #39 So far we have been running our application on the development workstation where the VB compiler created the MapCalc.AddMult class entry in our Registry. What if we want a different W2K server that has BIS to use our COM component? First we need to build an install package on our development workstation. Visual Studio provides a utility called the “Package and Deployment Wizard”. It will lead you through the steps for creating a install package. The files that it creates are the .CAB, the .LST and a Setup.exe. All you have to do is transfer these three files to the W2K server and run the Setup.exe. It will install the executable in the directory of your choice and make the necessary entries into the W2K server’s Registry. You may think that the install is a lot of work. But remember, the BIS COM Client Interface runs on the server . So, we only have to install our COM component on the server ; and not each workstation .
  • #41 Now let’s take a look at using the BIS / COM interface with other Microsoft COM components. We will show examples for e-mail, Excel and Word. In the process you will see how to find the prog-ids and interfaces of other COM components.
  • #42 Microsoft exposes a robust and complex set of components from its Office suite. If you are at all serious about developing a COM interface to any one of the Office modules, you should pick up this book.
  • #43 If you are running a website using Microsoft’s Internet Information Server (IIS), you will have a number of COM components in the CDONTS (Collaboration Data Objects for NT Server) library. If you scan the OLE Viewer tree for CDONTS classes you will find a NewMail class that can be used to send e-mail. It’s prog-id is CDONTS.NewMail. “ The CDO for NTS Library interfaces with the SMTP (Simple Mail Transfer Protocol) server component of Microsoft® Internet Information Server (IIS) version 4.0 and later.” “ The SMTP server component of IIS has its own message store mechanism. The Inbox and Outbox are mapped to directories in the file system, and no other folders exist. Message transfer takes place in such a way that spooling appears instantaneous, so the Inbox has no incoming queue and the Outbox is always empty.” “ When CDO for NTS is running with IIS, the Inbox is a single common folder shared by all SMTP recipients and applications. It contains all messages received by IIS and destined for the local domains for which the SMTP server is configured. However, the incoming messages are segregated by the CDO for NTS Library according to their recipients. An application can only access messages destined for the address it used when it logged on.” msdn.microsoft.com
  • #44 If you are running a website using Microsoft’s Internet Information Server (IIS), you will have a number of COM components in the CDONTS (Collaboration Data Objects for NT Server) library. If you scan the OLE Viewer tree for CDONTS classes you will find a NewMail class that can be used to send e-mail. It’s prog-id is CDONTS.NewMail. “ The CDO for NTS Library interfaces with the SMTP (Simple Mail Transfer Protocol) server component of Microsoft® Internet Information Server (IIS) version 4.0 and later.” “ The SMTP server component of IIS has its own message store mechanism. The Inbox and Outbox are mapped to directories in the file system, and no other folders exist. Message transfer takes place in such a way that spooling appears instantaneous, so the Inbox has no incoming queue and the Outbox is always empty.” “ When CDO for NTS is running with IIS, the Inbox is a single common folder shared by all SMTP recipients and applications. It contains all messages received by IIS and destined for the local domains for which the SMTP server is configured. However, the incoming messages are segregated by the CDO for NTS Library according to their recipients. An application can only access messages destined for the address it used when it logged on.” msdn.microsoft.com
  • #45 If we create a new Standard EXE VB project, add a Reference to the “Microsoft CDO for NTS 1.0” library, and then call up the Object Browser we will see the properties and methods for NewMail, a few of which are: Properties To -a string containing a comma separated list of recipients Cc -a string containing a comma separated list of recipients From -a string containing the from mail address Subject -a string containing the mail subject Body -text or HTML formatted mail body Methods AttachFile -attaches a file AttachURL -attaches a URL Send -sends the e-mail message
  • #46 Let’s walk through the BIS code that sends an e-mail using CDONTS: @CCC -create an instance of the NewMail class and save the instance handle @CCP -using the instance handle, Put strings into the From , To and Subject @BRK -build a result containing the message @LDV &lt;LF&gt;H1 -create a variable with the line-feed special character @CCP -using the instance handle, Put the results into BodyText @CCI -using the instance handle, invoke the Send method with no parameters @CCR -release the instance of NewMail Note: if we look at the format for the Send method: Send([From], [To], [Subject], [Body], [Importance]) we see that we could specify all the parameters on the Invoke method. But these parameters are all optional. So for BIS it may be easier to Put the values into the required properties and then perform a simple Send .
  • #47 If we scan the OLE Viewer tree for Microsoft Excel, we find that the most recent prog-id is Excel.Application.10.
  • #48 Using the Object Browser in VB we can uncover some of the structure of the Excel application, its collections, and interfaces (properties, methods and events). The complete object model is documented in the “Microsoft Office XP Developer’s Guide.” An Excel Application has Workbooks (files). Workbooks have Worksheets (sheets). Worksheets have Ranges (of cells). Each of these has a robust set of properties and methods so large that it will not fit on one slide. With BIS COM we would like access to all of these. But that becomes tricky because we only have five instance handles…
  • #49 You are beginning to get a feel for how the BIS COM statements work so I will not document each line of code here. But , there are several tricks to building a BIS / COM interface to Excel: First, you should initialize all the variables that you will be using as instance handles at the top of the code. Then set an RER. This will help avoid leaving any orphan processes. You have to have an NT sign-on (MPC sign-on in foreground or MAPPERguest user-id in background) that has access to all the directories, EXE’s and DLL’s that Excel needs. I am not sure what they are. I had to change my MPC script to use Administrator in order to get things to work. Any type of “Collection” (WorkBooks, Worksheets, Names) has an “Item” that we can be referenced as Item(1), Item(2), Item(3),… Since there are only five instance handles available in the COM client interface, we need to release the ones we no longer need. Regarding the last line: we would like to specify a range of cells using the row and column in a Range statement: Range(A1,C3) but we can’t. The @CCG only allows a “numerical index” (an integer) inside the parentheses.
  • #50 So we have to find something else that will let us specify a cell/range of cells. This is how we can do it: We get a handle to the Names collection We “Add” a “Name” and specify, in a string, the sheet and cell range to which it refers. The Add method will return a Name handle We use the “RefersToRange” of the Name to get the Range handle. Now we can GET and PUT using the Range handle. In the error handling/wrap-up section we should release any instance handle that is still open (value &gt; 0) to avoid orphan processes. We should also close any open workbooks; to keep them from remaining locked.
  • #51 So we have to find something else that will let us specify a cell/range of cells. This is how we can do it: We get a handle to the Names collection We “Add” a “Name” and specify, in a string, the sheet and cell range to which it refers. The Add method will return a Name handle We use the “RefersToRange” of the Name to get the Range handle. Now we can GET and PUT using the Range handle. In the error handling/wrap-up section we should release any instance handle that is still open (value &gt; 0) to avoid orphan processes. We should also close any open workbooks; to keep them from remaining locked.
  • #52 If we scan the OLE Viewer tree for Microsoft Word, we find that the most recent prog-id is Word.Application.10.
  • #53 Using the Object Browser in VB we can uncover some of the structure of the Word application, its collections, and interfaces (properties, methods and events). The complete object model is documented in the “Microsoft Office XP Developer’s Guide.” A Word Application has Documents (files). A Document has Sections, Paragraphs, Sentences, and Words. They also have Ranges or a Selection. You can have multiple Range’s. They will not be highlighted. They take less overhead. There is one and only one Selection. It belongs to the Application. The text in the Selection is highlighted. It takes slightly more overhead. Each of these (and more) has a robust set of properties and methods so large that it will not fit on one slide. With BIS COM we would like access to all of these. But that becomes tricky because we only have five instance handles.
  • #54 In this sample code we first predefine all our handle variables and set an RER (as we did with Excel). Then we Create a instance of Word.Application , get a handle to the Documents collection and use it to open our sample document. That returns a Document handle. Then we get handles to Application.Selection and Selection.Find . Here we show how we can use the Find.Execute method to do an Find/Replace on all occurrences of “!org!” with “Unite” (see format of Find.Execute function). Note that FindText and the ReplaceWith are strings, the “ 2 ” is a constant meaning all occurrences, and &lt;found&gt; is a boolean (0 or 1).
  • #55 Another way to do a Find/Replace is: do a Find.Execute , so that the selection is now highlighted, then do a Put (@CCP) of a string to Selection.Text . Before we try working with a table, we need to release a handle. To insert/populate a table we can do a Find.Execute followed by the Put (@CCP) of a result, and then do a Selection.ConvertToTable (see format of ConvertToTable function). Note that it returns a handle to the Table . If you do not specify the line-feed (&lt;lf&gt;) as a separator on the rid specification when you do the @CCP, only the first line will be inserted.
  • #56 So we have to find something else that will let us specify a cell/range of cells. This is how we can do it: We get a handle to the Names collection We “Add” a “Name” and specify, in a string, the sheet and cell range to which it refers. The Add method will return a Name handle We use the “RefersToRange” of the Name to get the Range handle. Now we can GET and PUT using the Range handle. In the error handling/wrap-up section we should release any instance handle that is still open (value &gt; 0) to avoid orphan processes. We should also close any open workbooks; to keep them from remaining locked.
  • #57 Using COM is not always the best way to build an interface to an Office module.
  • #59 The most frustrating and seeming endless process in building a BIS / COM interface is correctly setting up all the user-id’s and permissions. First, the W2K user-id needs “execute” permission on C:\\WINNT\\SYSTEM32 where OLE*.DLL’s are located. Then it needs “execute” permission on the directories where the .EXE’s and .DLL’s that it calls are located. For Excel and Word would include the whole Microsoft Office directory. Then it needs “read”, “write” and “modify” permissions to the directories that the .EXE’s and .DLL’s access.
  • #60 In the BIS manuals Unisys includes dozens of options and formats on the @CCG and @CCP statements but offers only one simple example for each statement. They really need examples for each option and format.
  • #61 Another area of frustration is working with programs like Excel and Word that have a Multiple Document Interface (MDI). How to do so is not explained in BIS manuals and Unisys gives no working examples. It took the Office XP Developer’s Guide and some trial and error before I was able to accomplish anything. Because of the number of objects used in these applications, five instance handles is not enough. We need at least sixteen. Interfaces to these programs is usually fairly robust and complex. Debugging the interface without being able to make the components visible is next to impossible.
  • #62 When a run errors off, or it completes without releasing all the instances that it created, you could be left with orphan processes that are difficult to stop. All too often you may have to reboot the machine to get rid of them.
  • #63 The BIS/COM interface has the potential for greatly expanding the system integration capabilities of your BIS applications. You should now have the knowledge base that will allow you to begin doing so.