CSCI 220 Programming With Visual Basic
Lecture 12: Alphabet Soup:
OLE, VBXs, DLLs, and the API

                              
 Overview of all features
  All are ways of extending VB
  All take advantage of Windows' unique architecture
  Programs can share code with each other
  Any windows language can use these features - details are
  different
     
The Windows API (Application Programming Interface)
  Description:
     Built into Windows
     A set of procedures and functions
     Work very much like VB functions and procedures
     Allows programmer to communicate directly with Windows
     Useful for those functions not included in VB that are
     supported by Windows
       (Sound, Advanced Graphics, External window
       management, etc)
  Declaration:
     Must be declared in Module or General part of form
     Declaration MUST follow windows specs exactly
     Frequent use of ByVal
     Case is important!!
     You NEED a book to explore API calls
  Procedure or function is used in code as if it had been
  written in VB
  Advantages:
     Allows use of otherwise unavailable features
     works with same speed as code written in any other
     language
     Allows more precise control of program features
  Disadvantages
     Declarations are ARCANE
     It's easy to truly mess up your program
     You need the guidance of a good book (have I said
     that?)
  
DLLs - Dynamic Link Libraries
  Description
     A set of procedures and functions written in another
     language (usually C) and compiled
     Procedures can also be used just like API calls
     ( the API is made up in part of DLLs !!!)
     Declaration and use is just like API calls
  Advantages
     for speed - sensitive work (sorting) DLL can be faster
     DLLs can be written to do things that VB can't do
     DLLs can be written by anybody proficient in C or
     Pascal for Windows
     Easy to use
  Disadvantages
     A DLL is worthless without perfect documentation
     Portability, royalty problems
     
     
VBXs  Visual Basic eXtensions
  Description
     A custom control or group of custom controls
     Use Add File from the File menu to choose a VBX
     Controls are added to the toolbar automatically
     Professional version is simply a set of VBX files
     Added VBX files are listed in Project Window
     Common Dialog, Grid, and OLE2 are VBXs added by our
     system
     New controls are used much like any other controls
  Advantages
     As easy and convenient as original VB
     Seamless integration into VB
  Disadvantages
Portability, royalty problems

OLE Object Linking and Embedding
  Different use for the term object
  Description
     A program or part of a program (object) can be accessed
     as part of another program
     An object program written for one program can often be
     used by others
     User sees results of object program or icon
     By double-clicking on object, user activates object
     program
  Embedded
     Object program does not have separate data file.
     Data is stored with host document or program
     Host CONTAINS object
     Object can only be changed by accessing it with its own
     host document
     Can be created from scratch or be copied from an
     existing entity (some objects)
     If copied, original does not change when object is
     manipulated.
  Linked
     Object must be created from an existing file
     Host document does not contain object
     Host only holds links to the object in the file
     If the object is changed in any way, all documents that
     link to that object will reflect the changes
     Uses:  A spreadsheet chart in a WP document, a map in
     several documents
  Using it in VB
     Use the OLE2 control
     Draw a box on the form
     A window will come up asking you what kind of object
     you want to attach
     (This list will vary by computer)
     This dialogue also allows you to choose between linking
     & embedding, and allows you to attach to an existing
     file if you wish
     When user double-clicks on object, it will activate
     Right button allows verb menu of object
     Use properties to change viewing options, methods of
     activation, etc
     Use SourceItem property to select the object after
     initial placement of object
  Advantages:
     Allows UNBELIEVABLE capabilities with little
     programming
     Gives you the chance to use professional programs
     inside your own
  Disadvantages:
     Requires large amounts of memory
     VERY picky about system setup
     Chancy portability - depends on user having objects
     installed and accessible
Return to Syllabus