![]() |
Oracle
COM Automation Developer's Guide
Release 8.1.5 for Windows NT A68012-01 |
|
This chapter describes the core functionality of Oracle COM
Automation feature.
Specific topics discussed are:
Oracle COM Automation feature provides a mechanism to manipulate COM objects. It acts as a generic wrapper interface of the IDispatch interface (OLE Automation).
When an Oracle COM Automation feature API is invoked from PL/SQL, the feature converts the parameters to the appropriate OLE Automation data types and then invokes the corresponding IDispatch API with the converted parameters. The feature externalizes the following APIs:
This section describes each of the APIs and how to use them in PL/SQL blocks. A typical PL/SQL block performs the following steps to create and manipulate a COM object using Oracle COM Automation feature:
Oracle COM Automation feature enables you to use components that provide additional functionality that PL/SQL does not support. As mentioned before, you can choose to build your own custom components or use the thousands of pre-built components that are available from third-party ISVs. However, before you can begin building a solution using Oracle COM Automation feature, you must know two things about the COM objects that you intend to use.
[id(0x6003000)] long Post( [in, out] long* lngAccountNo, [in, out] long* lngAmount, [in, out] BSTR* strResult);
Microsoft provides a tool called the OLE/COM Object Viewer
with Microsoft Visual C++ for browsing the properties and methods of COM
objects on a local system. This tool enables you to quickly and easily
determine the properties and methods that each COM object exposes.
Because Oracle uses PL/SQL datatypes and OLE Automation uses
Microsoft Visual Basic datatypes, Oracle COM Automation feature must convert
the data that it receives from PL/SQL and pass it to the OLE Automation
object, and vice versa.
This table shows the conversion from PL/SQL datatypes to
Microsoft Visual Basic datatypes:
PL/SQL Datatype | Microsoft Visual Basic Datatype |
---|---|
Varchar2 |
String |
Boolean |
Boolean |
Binary_Integer |
Byte, Integer, or Long |
Double Precision |
Double, Single, or Currency |
Date |
Date |
This table shows the conversion from Microsoft Visual Basic
datatypes to PL/SQL datatypes:
Microsoft Visual Basic Datatype | PL/SQL Datatype |
---|---|
Boolean |
Boolean |
Long, Integer, Byte, Object |
Binary_Integer |
String |
VarChar2 |
Double, Single, or Currency |
Double Precision |
Date |
Date |
These APIs return an integer return code. The return code
is 0 when successful or a non-zero HRESULT when an error occurs. An HRESULT
is an OLE error code of the hexadecimal form 0x800nnnnn, but when
it is returned as a binary_integer value, it has the form -214nnnnnnn.
For example, passing an invalid object name to CreateObject
causes it to return a binary_integer HRESULT of -2147221005, which is 0x800401f3
in hexadecimal.
The sections on GetLastError and OLE Automation errors provide
additional information on how to interpret the return codes from Oracle
COM Automation feature. For complete information on HRESULTs, refer to
the Microsoft documentation on HRESULTs.
The following section describes the PL/SQL APIs for manipulating
COM objects using the OLE Automation interface. Each of the following PL/SQL
stored procedures reside in the package ORDCOM.
Instantiates a COM object in an OLE Automation server.
FUNCTION CreateObject(progid VARCHAR2, reserved BINARY_INTEGER, servername VARCHAR2, objecttoken OUT BINARY_INTEGER) RETURN BINARY_INTEGER;
The created OLE Automation object must be freed with a corresponding
call to DestroyObject. This nullifies the internal representation of the
object in the Oracle COM Automation Feature and releases all the interfaces
associated with the object. If you do not free the object, the object stays
resident until the user's session terminates.
This procedure returns a 0 when successful or a non-zero
HRESULT when an error occurs.
hresult binary_integer; applicationToken binary_integer:=-1; hresult :=ORDCOM.CreateObject('Excel.Application', 0, `', applicationToken); IF hresult = -1 THEN dbms_output.put_line(hresult); END IF;
Destroys a created OLE Automation object.
FUNCTION DestroyObject(objecttoken BINARY_INTEGER) RETURN BINARY_INTEGER;
objecttoken |
is the object token of an OLE Automation object previously created by CreateObject. |
If DestroyObject is not called, the created OLE Automation
object stays resident until the user's session is terminated. Calling DestroyObject
nullifies the internal representation of the object in the Oracle COM Automation
Feature and releases all the interfaces associated with the object.
This procedure returns a 0 when successful or a non-zero
HRESULT when an error occurs.
hresult binary_integer; applicationToken binary_integer:=-1; /* At some point before this, we called CreateObject and got a valid applicationToken. */ hresult:=ORDCOM.DestroyObject(applicationToken);
Obtains the OLE Automation error information about the last
error that occurred.
FUNCTION GetLastError(source OUT VARCHAR2, description OUT VARCHAR2, helpfile OUT VARCHAR2, helpid OUT VARCHAR2) RETURN BINARY_INTEGER;
Each call to an Oracle COM Automation feature API (except
GetLastError)
resets the error information, so that
GetLastError obtains error
information only for the most recent Oracle COM Automation feature API
call. Because
GetLastError does not reset the last error information,
it can be called multiple times to get the same error information.
This procedure returns a 0 when successful or a non-zero
HRESULT when an error occurs.
See "OLE Automation Errors" for a
description of the types of errors that can be returned by this function.
applicationToken binary_integer:=-1; hresult binary_integer; error_src varchar2(255); error_description varchar2(255); error_helpfile varchar2(255); error_helpID binary_integer; hresult:=ORDCOM.CreateObject('Excel.Application', 0, `', applicationToken); IF hresult=-1 THEN ORDCOM.GetLastError(error_src, error_description, error_helpfile, error_ helpID); dbms_output.put_line(error_src); dbms_output.put_line(error_description); dbms_output.put_line(error_helpfile); return hresult; END IF;
Gets a property value of an OLE Automation object.
FUNCTION GetProperty(objecttoken BINARY_INTEGER, propertyname VARCHAR2, argcount BINARY_INTEGER, propertyvalue OUT any PL/SQL datatype) RETURN BINARY_INTEGER;
If the property returns an OLE object, you must specify a
local variable of datatype binary_integer or the propertyvalue parameter.
An object token is stored in the local variable, and this object token
can be used with other OLE Automation stored procedures.
When the property returns an array, if
propertyvalue
is specified, it is set to NULL.
This procedure returns a 0 when successful or a non-zero
HRESULT when an error occurs.
ChartObject binary_integer:=-1; CharToken binary_integer := -1 hresult binary_integer; /* Previously, ChartObject, CharToken were initialized calling CreateObject */ hresult:=ORDCOM.getProperty(ChartObject, 'Chart', 0, ChartToken); IF hresult=-1 THEN /* Do error checking here */ return hresult; END IF;
Sets a property of an OLE Automation object to a new value.
FUNCTION SetProperty(objecttoken BINARY_INTEGER, propertyname VARCHAR2, newvalue ANY PL/SQL DATATYPE, datatype VARCHAR2) RETURN BINARY_INTEGER;
This procedure returns a 0 when successful or a non-zero
HRESULT when an error occurs.
RangeToken binary_integer:=-1; hresult binary_integer; /* Previously, RangeToken has been initialized to a valid object token with a property by the name of value. */ hresult:=ORDCOM.SetProperty(RangeToken, 'Value', `EmpNo', `BSTR'); IF hresult=-1 THEN /* Do error checking here */ return hresult; END IF;
Initializes the parameter set to pass to an Invoke call.
PROCEDURE InitArg();
Each SetArg or SetPtrArg procedure sets the
nth
parameter value. The InitArg call initializes the parameter set.
After InitArg has been called, a SetArg or SetPtrArg call sets the first
parameter to the specified value. A second SetArg or SetPtrArg call sets
the second parameter in the parameter list. Subsequent calls set the nth
parameters in the parameter list, where n is the number of times
SetArg or SetPtrArg has been called after an InitArg call. Another call
to InitArg resets the argument list and a call to SetArg or SetPtrArg sets
the first parameter again.
See "Invoke" for sample code.
Used to construct the parameter list for the next
Invoke
call. SetArg sets a parameter's value to be passed by value.
PROCEDURE SetArg(paramvalue ANY PL/SQL DATATYPE, datatype VARCHAR2);
Each SetArg or SetPtrArg procedure sets the
nth
parameter value. The InitArg call initializes the parameter set.
After InitArg has been called, a SetArg or SetPtrArg call
sets the first parameter to the specified value. A second SetArg or
SetPtrArg call sets the second parameter in the parameter list. Subsequent
calls set the
nth parameters in the parameter list, where n
is the number of times SetArg or SetPtrArg has been called after an InitArg
call. Another call to InitArg resets the argument list and a call to
SetArg
or SetPtrArg sets the first parameter again.
See "Invoke" for sample code.
Constructs the parameter list for the next Invoke
call. SetPtrArg sets a parameter's value to be passed by reference.
PROCEDURE SetPtrArg(paramvalue ANY PL/SQL DATATYPE, datatype VARCHAR2);
Each SetArg or SetPtrArg procedure sets the
nth
parameter value. The InitArg call initializes the parameter set.
After InitArg has been called, a SetArg or SetPtrArg call
sets the first parameter to the specified value. A second SetArg or
SetPtrArg call sets the second parameter in the parameter list. Subsequent
calls set the
nth parameters in the parameter list, where n
is the number of times SetArg or SetPtrArg has been called after an InitArg
call. Another call to InitArg resets the argument list and a call to
SetArg
or SetPtrArg sets the first parameter again.
See "Invoke" for sample code.
Calls a method of an OLE Automation object. This function
uses the parameter list, previously created by the calls to InitArg, SetArg,
and SetPtrArg, as input for the OLE Automation method.
FUNCTION Invoke(objecttoken BINARY_INTEGER, methodname VARCHAR2, argcount BINARY_INTEGER, returnvalue OUT ANY PL/SQL DATATYPE) RETURN BINARY_INTEGER;
If the method's return value is an OLE object, then the developer
must specify a local variable of datatype binary_integer for the returnvalue
parameter. An object token is stored in the local variable, and this object
token can be used with other Oracle COM Automation feature APIs.
This procedure returns a 0 when successful or a non-zero
HRESULT when an error occurs.
xpos binary_integer; ypos binary_integer; width binary_integer; height binary_integer; WorkSheetToken binary_integer:=-1; ChartObjectToken binary_integer:=-1; ChartObject binary_integer:=-1; hresult binary_integer; /*WorkSheetToken has been initialized with a valid OLE Automation object */ /* Executes a method that takes 0 arguments */ ORDCOM.InitArg(); i:=ORDCOM.Invoke(WorkSheetToken, 'ChartObjects', 0, ChartObjectToken); /* Executes a method that takes 4 arguments */ ORDCOM.InitArg(); ORDCOM.SetArg(xpos,'I2'); ORDCOM.SetArg(ypos,'I2'); ORDCOM.SetArg(width,'I2'); ORDCOM.SetArg(height,'I2'); i:=ORDCOM.Invoke(ChartObjectToken, 'Add', 4, ChartObject);
The following is a list of OLE Automation errors and their common causes.
(0x800401f3)
Invalid class string
Cause: The specified ProgID or CLSID is not registered
as an OLE object in the registry of the local computer.
(0x8007007e)
The specified module could not be found
Cause: The specified OLE object is registered as an
in-process OLE server (.DLL file), but the .DLL file could not be found
or loaded.
(0x80020004)
Parameter not found
Cause: A named parameter was specified before a positional parameter.
Action: Ensure that all named parameters are specified
after all positional parameters.
Cause: The datatype of a PL/SQL local variable used to store a returned property value or a method return value did not match the Visual Basic data type of the property or method return value.
Action: Ensure that the local
variable is of the appropriate datatype. Or, the return value of a property
or a method was requested, but it does not return a value.
Cause: The specified property
or method name was not found for the specified object.
(0x80020008)
Bad variable type
Cause: The datatype of a PL/SQL value passed as a method parameter did not match the Microsoft Visual Basic data type of the method parameter, or a NULL value was passed as a method parameter.
Action: Ensure that any local
variables used as method parameters are of the appropriate datatype and
are set to a value other than NULL.
(0x80080005)
Server execution failed
Cause: The specified OLE object is registered as a local OLE server (.EXE file), but the .EXE file could not be found or started.
|
![]() Copyright © 1999 Oracle Corporation. All Rights Reserved. |
|