EventSinkEnumEvnts
f90VB Modules
f90VBDefs, f90VBVariants, f90VBAutomation
Summary
Enumerates the events exposed by the outgoing interface of an Automation object.
Syntax
| subroutine EventSinkEnumEvnts | (EventSink, EventsList, iRet) |
| integer(POINTER_KIND),intent(in):: | EventSink |
| type(VARIANT),intent(out):: | EventsList |
| integer(HRESULT_KIND),intent(out),optional:: | iRet |
Arguments
EventSink [Input]
A handle to an event sink object with an active connection to an outgoing interface.
EventsList [Output]
A variant that, upon return, contains an Safe Array of Variants describing the events that can be fired by the outgoing interface of the Automation object to which the event sink is connected.
iRet [Output/Optional]
Upon return, iRet contains S_OK or an error code.
Comments
Use subroutine EventSinkEnumEvnts to obtain a list of events and their DispIDs available in a event sink object that has been connected to an outgoing interface of an automation server. If this procedure is called on a disconnected event sink, it returns an error condition in argument iRet.
Argument EventList
The description of the events exposed by an object are returned in this argument as a Variant containing a reference to a Safe Array of Variants. The Safe Array has one row per event function exposed by the Automation object, and four columns. The information is each is as follows:
Column 1: Contains the Dispatch ID (DispID) of the event function.
Column 2: Contains a BString with the name of the event function.
Column 3: Contains the number of arguments used by the event function.
Column 4: Contains the address of the Fortran function that handles the event, or 0 if no Fortran function has been registered to handle the event.
Examples
| program EnumerateEventsExample |
!Demonstrates use of EventSinkEnumEvnts
!of the EventSink facility in f90VBAutomation
!Copyright (C) 1999-2000, Canaima Software, Inc.
!All rights reserved
use f90VBDefs
use f90VBBstrings
use f90VBSafeArrays
use f90VBVariants
use f90VBAutomation
implicit none
!Variants containing main objects
type(VARIANT)::Excel, Workbook
!Event sink handle
integer(POINTER_KIND)::AppEventSinkHndl, WBEventSinkHndl
integer(HRESULT_KIND)::iRet
type(VARIANT)::EventList
type(VARIANT),pointer::MapArray(:,:)
character(len=100)::EventName
integer::i
!Initialize Ole
iRet = OleInitialize()
!Get an instance of Excel
Excel = GetActiveOleObject('Excel.Application', iRet)
if (iRet.ne.S_OK) then
!no instances of Excel are running, create one
Excel = CreateOleObject('Excel.Application', iRet)
if (iRet.ne.S_OK) then
print *,'You need Excel installed'
print *,'for this program to work'
goto 1000
endif
!Makes the IE object visible
call PropertyPut(Excel,'Visible',VariantCreate(VT_BOOL,.true.))
endif
!Create an f90VBAutomation Event Sink for the Application object
AppEventSinkHndl = EventSinkCreate()
!Connects the Event Sink to the default Excel events interface
call EventSinkConnect(AppEventSinkHndl, Excel, NullGUID())
!Get a list of available events from the Event Sink object
call EventSinkEnumEvnts(AppEventSinkHndl, EventList)
!Map the array of variants returned by EventSinkEnumEvnts
!into a Fortran Array for easy access
call SafeArrayAccessData(EventList%VarVal%pArray,MapArray)
!print the list of events. Note that we have not registered
!any Fortran handler for these events, so the Event Handler
!Address is null in all cases
print *,'Events in Excel Application Object:'
write(*,'(a8,a25,a10,a25)') 'DispID','Event Name', &
'Arguments','Event Handler Address'
do i=lbound(MapArray,1),ubound(MapArray,1)
!Convert Bstring with member name into a Fortran string
call StrCopy(MapArray(i,2)%VarVal%bstrVal, EventName)
!print information for the member
write(*,'(i8,a25,i10,i25)') VariantToInteger(MapArray(i,1)), &
Trim(EventName), &
VariantToInteger(MapArray(i,3)), &
VariantToInteger(MapArray(i,4))
enddo
!Release the Fortran array mapping
call SafeArrayUnaccessData(EventList%VarVal%pArray)
!Clear Event list
call VariantClear(EventList)
!Add a new workbook by calling Workbooks.Add method
WorkBook=ExecMethod(Excel,'Workbooks.Add')
!Create a second event sink object, connected to the
!workbook object and list its events
WBEventSinkHndl = EventSinkCreate()
call EventSinkConnect(WBEventSinkHndl, WorkBook, NullGUID())
!Get a list of available events from the Event Sink object
call EventSinkEnumEvnts(WBEventSinkHndl, EventList)
!Map the array of variants returned by EventSinkEnumEvnts
call SafeArrayAccessData(EventList%VarVal%pArray,MapArray)
!print the list of events
print *,'Events in Workbook Object:'
write(*,'(a8,a25,a10,a25)') 'DispID','Event Name', &
'Arguments','Event Handler Address'
do i=lbound(MapArray,1),ubound(MapArray,1)
!Convert Bstring with member name into a Fortran string
call StrCopy(MapArray(i,2)%VarVal%bstrVal, EventName)
!print information for the member
write(*,'(i8,a25,i10,i25)') VariantToInteger(MapArray(i,1)), &
Trim(EventName), &
VariantToInteger(MapArray(i,3)), &
VariantToInteger(MapArray(i,4))
enddo
!Release the Fortran array mapping
call SafeArrayUnaccessData(EventList%VarVal%pArray)
!Clear Event list
call VariantClear(EventList)
!Destroy (and disconnect) Event sink objects
call EventSinkDestroy(WBEventSinkHndl)
call EventSinkDestroy(WBEventSinkHndl)
1000 continue
!clear variants and releases objects
call VariantClear(WorkBook)
call VAriantClear(Excel)
call OleUninitialize()
stop
end
Related Topics
| For information about: | See: | |
| Creating an event sink object | EventSinkCreate | |
| Connecting an event sink to a connectable object | EventSinkConnect | |
| Registering/Unregistering Fortran event handlers | EventSinkRegEvnt /EventSinkUnregEvnt | |