contents   index   previous   next



Using f90VB to control ActiveX objects

 

Now that you have at least a general understanding of COM and Automation, this section will show you how to use the facilities available in the f90VB Automation library to create Automation controllers in Fortran.

 

A client application accessing an ActiveX object through its Automation interfaces must follow a series of steps:

 

Initialize OLE.

 

Create an instance of the object you want to access. The object's ActiveX server creates the object.

 

Obtain a reference to the object's IDispatch interface (if it has implemented one).

 

Manipulate the object through the methods, properties and events exposed.

 

Terminate the object by invoking the appropriate method in its IDispatch interface, or by releasing all references to the object.

 

Uninitialize OLE.

 

The f90VB Automation library provides all the basic functions you need to perform these steps. In this section we’ll be using Example 6.1, which automates Internet Explorer to load f90VB’s home page from Canaima Software’s web server.

 

 

 

 

 

Example 6.1

 

This is a very simple example that creates an instance of Internet Explorer and asks the browser to load f90VB’s Home Page. Note that you need to have an Internet connection open before executing this program, or have Internet Explorer configured to automatically dial in to your Internet Service Provider. Otherwise you will get a Page cannot be displayed message.

 

program Example61

 

use f90VBDefs

use f90VBVariants

use f90VBAutomation

 

!Variants containing main objects

type(VARIANT)::IE

!Variants used to stored temporal objects and collections

type(VARIANT)::VarTmp,URL

 

integer(HRESULT_KIND)::iRet

 

integer::i

real::k

type(variant)::IsVisible

 

!Initialize Ole

iRet = OleInitialize()

 

!Get an instance of Internet Explorer

IE = CreateOleObject('InternetExplorer.Application', iRet)

 

!Set the visible property of the browser so it appears on the screen

call PropertyPut(IE,'Visible',VariantCreate(VT_BOOL,.true.),iRet=iRet)

 

!Execute the Navigate Method

URL=VariantCreate(VT_BSTR,'www.canaimasoft.com/f90VB')

VarTmp = ExecMethod(IE,'Navigate',URL,iRet=iRet)

 

!Release the instance to IE, leaving the browser on

call Release(IE)

 

!Clean up variants

call VariantClear(URL)

call VariantClear(VarTmp)

 

!Uninitialize Ole

call OleUninitialize()

 

stop

end

 

 

USE-ing f90VB Modules