Creating OLE automation routines
OLE automation routines are implemented as public methods of OLE automation objects.
About this task
The OLE automation objects must be creatable by an OLE automation controller out side of the database and support late binding (also called IDispatch-based binding). OLE automation objects must be registered in the Windows registry with a class identifier (CLSID), and optionally, an OLE programmatic ID (progID) to identify the automation object. The progID can identify an in-process (.DLL) or local (.EXE) OLE automation server, or a remote server through DCOM (Distributed COM).
Procedure
To register OLE automation routines:
After you code an OLE automation object, you need to create
the methods of the object as routines using the CREATE statement.
Creating OLE automation routines is very similar to registering C
or C++ routines, but you must use the following options:
- LANGUAGE OLE
- FENCED NOT THREADSAFE, because OLE automation routines must run in FENCED mode, but cannot be run as THREADSAFE.
The external name consists of the OLE progID
identifying the OLE automation object and the method name separated
by
!
(exclamation mark): CREATE FUNCTION bcounter () RETURNS INTEGER
EXTERNAL NAME 'bert.bcounter!increment'
LANGUAGE OLE
FENCED
NOT THREADSAFE
SCRATCHPAD
FINAL CALL
NOT DETERMINISTIC
NULL CALL
PARAMETER STYLE DB2SQL
NO SQL
NO EXTERNAL ACTION
DISALLOW PARALLEL;
The calling conventions for OLE
method implementations are identical to the conventions for routines
written in C or C++. An implementation of the previous method in the
BASIC language looks like the following (notice that in BASIC the
parameters are by default defined as call by reference): Public Sub increment(output As Long, _
indicator As Integer, _
sqlstate As String, _
fname As String, _
fspecname As String, _
sqlmsg As String, _
scratchpad() As Byte, _
calltype As Long)