Oracle COM Automation Feature Developer's Guide 10g Release 2 (10.2) B14310-02
Oracle COM Automation Feature Developer's Guide 10g Release 2 (10.2) B14310-02
Developer's Guide
10g Release 2 (10.2)
B14310-02
November 2005
Oracle COM Automation Feature Developer’s Guide, 10g Release 2 (10.2)
B14310-02
Contributors: Janis Greenberg, Eric Belden, Steven Caminez, Jagadish Changavi, Barmak Meftah, Valarie
Moore, Neeraj Gupta, Vikhram Shetty, Sujith Somanathan, Alex Keh, Christian Shay, Riaz Ahmed
The Programs (which include both the software and documentation) contain proprietary information; they
are provided under a license agreement containing restrictions on use and disclosure and are also protected
by copyright, patent, and other intellectual and industrial property laws. Reverse engineering, disassembly,
or decompilation of the Programs, except to the extent required to obtain interoperability with other
independently created software or as specified by law, is prohibited.
The information contained in this document is subject to change without notice. If you find any problems in
the documentation, please report them to us in writing. This document is not warranted to be error-free.
Except as may be expressly permitted in your license agreement for these Programs, no part of these
Programs may be reproduced or transmitted in any form or by any means, electronic or mechanical, for any
purpose.
If the Programs are delivered to the United States Government or anyone licensing or using the Programs on
behalf of the United States Government, the following notice is applicable:
U.S. GOVERNMENT RIGHTS Programs, software, databases, and related documentation and technical data
delivered to U.S. Government customers are "commercial computer software" or "commercial technical data"
pursuant to the applicable Federal Acquisition Regulation and agency-specific supplemental regulations. As
such, use, duplication, disclosure, modification, and adaptation of the Programs, including documentation
and technical data, shall be subject to the licensing restrictions set forth in the applicable Oracle license
agreement, and, to the extent applicable, the additional rights set forth in FAR 52.227-19, Commercial
Computer Software--Restricted Rights (June 1987). Oracle Corporation, 500 Oracle Parkway, Redwood City,
CA 94065
The Programs are not intended for use in any nuclear, aviation, mass transit, medical, or other inherently
dangerous applications. It shall be the licensee's responsibility to take all appropriate fail-safe, backup,
redundancy and other measures to ensure the safe use of such applications if the Programs are used for such
purposes, and we disclaim liability for any damages caused by such use of the Programs.
Oracle, JD Edwards, PeopleSoft, and Retek are registered trademarks of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective owners.
The Programs may provide links to Web sites and access to content, products, and services from third
parties. Oracle is not responsible for the availability of, or any content provided on, third-party Web sites.
You bear all risks associated with the use of such content. If you choose to purchase any products or services
from a third party, the relationship is directly between you and the third party. Oracle is not responsible for:
(a) the quality of third-party products or services; or (b) fulfilling any of the terms of the agreement with the
third party, including delivery of products or services and warranty obligations related to purchased
products or services. Oracle is not responsible for any loss or damage of any sort that you may incur from
dealing with any third party.
Contents
iii
Configuring Oracle COM Automation Feature for Java .............................................................. 2-3
Configuring the Listener for PL/SQL ................................................................................................... 2-4
Troubleshooting Listener Problems ................................................................................................ 2-5
Support for DCOM .................................................................................................................................. 2-5
Configurations for the Computer Running the Database Instance ............................................ 2-6
Setting Services to a Domain User............................................................................................ 2-6
Configuring the Computer Containing the Remote Object ......................................................... 2-6
iv
4 Oracle COM Automation PL/SQL Demos
Overview of PL/SQL Demos ................................................................................................................. 4-1
Microsoft Word Demo ............................................................................................................................. 4-1
Installing the Microsoft Word Demo .............................................................................................. 4-2
Using the Microsoft Word Demo..................................................................................................... 4-2
Core Functionality.............................................................................................................................. 4-2
Microsoft Excel Demo ............................................................................................................................. 4-5
Installing the Microsoft Excel Demo ............................................................................................... 4-5
Using the Microsoft Excel Demo...................................................................................................... 4-5
Core Functionality.............................................................................................................................. 4-6
Microsoft PowerPoint Demo.................................................................................................................. 4-8
Installing the Microsoft PowerPoint Demo.................................................................................... 4-8
Using the Microsoft PowerPoint Demo .......................................................................................... 4-8
Core Functionality.............................................................................................................................. 4-9
MAPI Demo............................................................................................................................................ 4-10
Setting Up the Environment to Use the MAPI Demo................................................................ 4-11
Preparing to Install MAPI Demo .................................................................................................. 4-11
Installing the MAPI Demo ............................................................................................................. 4-12
Using the MAPI Demo ................................................................................................................... 4-12
Core Functionality........................................................................................................................... 4-13
Glossary
Index
v
vi
Preface
Audience
Oracle COM Automation Feature Developer’s Guide is intended for developers who
develop solutions that use COM.
To use this document, you need familiarity with:
■ Component Object Model (COM)
■ Object Linking and Embedding (OLE) Automation
■ Structured Query Language (SQL)
■ Data Definition Language (DDL)
■ Data Manipulation Language (DML)
■ PL/SQL or Java
■ Oracle object-relational database management (ORDBMS) concepts
■ Windows Server Operating Systems
Documentation Accessibility
Our goal is to make Oracle products, services, and supporting documentation
accessible, with good usability, to the disabled community. To that end, our
documentation includes features that make information available to users of assistive
technology. This documentation is available in HTML format, and contains markup to
facilitate access by the disabled community. Accessibility standards will continue to
evolve over time, and Oracle is actively engaged with other market-leading
vii
technology vendors to address technical obstacles so that our documentation can be
accessible to all of our customers. For more information, visit the Oracle Accessibility
Program Web site at
http://www.oracle.com/accessibility/
Related Documents
For more information, see these Oracle resources:
■ Oracle Database Installation Guide for Windows
■ Oracle Database Release Notes for Windows
■ Oracle Database Platform Guide for Windows
■ Oracle Services for Microsoft Transaction Server Developer's Guide
■ Oracle Net Services Administrator's Guide
■ Real Application Clusters Quick Start
■ Oracle Database New Features
■ Oracle Database Concepts
■ Oracle Database Reference
■ Oracle Database Java Developer's Guide
For information about Oracle error messages, see Oracle Database Error Messages.
Oracle error message documentation is available only in HTML. If you only have
access to the Oracle Documentation CD, you can browse the error messages by range.
Once you find the specific range, use your browser's "find in page" feature to locate the
specific message. When connected to the Internet, you can search for a specific error
message using the error message search feature of the Oracle online documentation.
Many of the examples in this book use the sample schemas of the seed database, which
is installed by default when you install Oracle. Refer to Oracle Database Sample Schemas
for information on how these schemas were created and how you can use them
yourself.
Printed documentation is available for sale in the Oracle Store at
http://oraclestore.oracle.com/
viii
To download free release notes, installation documentation, white papers, or other
collateral, please visit the Oracle Technology Network (OTN). You must register online
before using OTN; registration is free and can be done at
http://otn.oracle.com/membership/
If you already have a username and password for OTN, then you can go directly to the
documentation section of the OTN Web site at
http://otn.oracle.com/documentation/
Conventions
The following text conventions are used in this document:
Convention Meaning
boldface Boldface type indicates graphical user interface elements associated
with an action, or terms defined in text or the glossary.
italic Italic type indicates book titles, emphasis, or placeholder variables for
which you supply particular values.
monospace Monospace type indicates commands within a paragraph, URLs, code
in examples, text that appears on the screen, or text that you enter.
ix
x
What’s New in Oracle COM Automation
Feature?
The following sections describe the new features in Oracle Oracle COM Automation
Feature:
■ Oracle Database 10g Release 2 (10.2) New Features in Oracle COM Automation
Feature
■ Oracle Database 10g Release 1 (10.1) New Features in Oracle COM Automation
Feature
■ Oracle Release 9.2 New Features in Oracle COM Automation Feature
■ Oracle9i New Features in Oracle COM Automation Feature
■ Oracle Release 8.1.6 New Features in Oracle COM Automation Feature
xi
Oracle9i New Features in Oracle COM Automation Feature
This section contains these topics:
■ Using Oracle9i on Windows 2000
There are some differences between using Oracle9i on Windows 2000 and
Windows NT 4.0.
■ Sample Schema
Many of the examples in this book use the sample schemas of the seed database,
which is installed by default. Refer to Oracle Database Sample Schemas for
information on how these schemas were created and how you can use them
yourself.
■ New Functionality to Support Java Stored Procedures
Oracle COM Automation Feature is now available for Java as well as PL/SQL.
While the general functionality is parallel, this document indicates those areas
where functionality, setup, and architecture differ.
■ orawpcom.dll Replaces com81.dll
For this release, Oracle has renamed the com81.dll to orawpcom.dll. If you are
migrating from Oracle8i, you must rerun comwrap.sql to continue using Oracle
COM Automation Feature for PL/SQL.
xiii
xiv Oracle COM Automation Feature Developer’s Guide
1
Introducing Oracle COM Automation Feature
This chapter describes the Oracle COM Automation Feature Software Development
Kit (SDK) and provides an overview of the product. Read this chapter before installing
or using Oracle COM Automation Feature.
This chapter contains these topics:
■ Introduction to Oracle COM Automation Feature
■ Benefits of Oracle COM Automation Feature
■ Oracle COM Automation Feature Architecture
Microsoft Office
Oracle (Word, Powerpoint,
Net and Excel)
Client PC
Oracle
Net Oracle Any COM
database
with COM Automation
feature Server
Client PC
Oracle
Net MAPI Compliant
Applications
Client PC
The architectural differences between Oracle COM Automation Feature for PL/SQL
and for Java are described in the next two sections.
PL/SQL Architecture
Oracle COM Automation Feature for PL/SQL provides a package of PL/SQL APIs for
manipulating COM objects. These APIs are implemented as external procedures in a
Dynamic Link Library (DLL).
Oracle9i supports external procedures that enable developers to call Third Generation
Language (3GL) functions from server-based object type methods and stored
procedures. External procedures are invoked exactly like standard PL/SQL stored
procedures. However, unlike standard PL/SQL procedures where the body of the
procedure is written in PL/SQL and stored in the database, external procedures are
functions in the C programming language that reside within a DLL. You can invoke
Oracle COM Automation Feature APIs in the same manner in which you call a
standard PL/SQL stored procedure or function.
Figure 1–2, "COM Automation Feature Architecture for PL/SQL" shows an Oracle9i
database invoking COM Automation external procedure APIs.
PL/SQL script
(any stored
procedure, function,
or trigger)
Oracle
Oracle Listener
Database
Instance Oracle Net
RPC
External
Procedure
Handler
Data
Store
COM Automation
COM feature Server (In-process,
COM Local, or Remote)
or DCOM
Java Architecture
Oracle COM Automation Feature for Java is implemented by the Java Native Interface
(JNI) as shown in Figure 1–3, "COM Automation Feature Architecture for Java".
The key components of this architecture are the Automation class and the Java COM
Proxy DLL, orawcomVER.dll, where VER is the release version.
The interface is the Automation class, a Java proxy to COM Automation server. The
Automation class provides the methods necessary for developers to manipulate
COM objects through the IDispatch interface.
The Java-specific COM proxy, orawcomVER.dll, enables Java functions to invoke
their corresponding COM functions.
Java Stored
Procedures
Oracle Automation
Database class
Instance
Reliability
Oracle COM Automation Feature for Java invokes COM components from the
database server. However, these COM components are run outside of the Oracle9i
database process. This design prevents unstable COM components from interfering
with the database process.
This chapter provides an overview of the Oracle COM Automation installation and
postinstallation configuration tasks.
This chapter contains these topics:
■ Oracle COM Automation Feature Components
■ System Requirements
■ Migration from Oracle9i to Oracle Database 10g
■ Migration from Oracle8i to Oracle Database 10g
■ Configurations for Oracle COM Automation Feature
■ Configuring the Listener for PL/SQL
■ Support for DCOM
See Also: The Oracle Database Installation Guide for Windows for
installation instructions
The COM Automation package includes the following PL/SQL and Java components:
PL/SQL Components
■ Oracle COM Automation PL/SQL feature (orawpcomVER.dll)
■ PL/SQL installation and definition script (comwrap.sql)
■ Oracle COM Automation demonstration programs
■ Message files (such as comus.msb)
Oracle COM Automation PL/SQL feature orawpcomVER.dll is located in the
ORACLE_BASE\ORACLE_HOME\bin directory.
All other components are located in the ORACLE_BASE\ORACLE_HOME\com directory.
Java Components
The Java components for Oracle COM Automation Feature are:
■ The JAR file, orawcom.jar
■ Oracle COM Automation Java feature (orawcomVER.dll)
■ Oracle COM Automation demonstration programs
■ grant.sql
Oracle COM Automation Java feature orawcomVER.dll is located in the ORACLE_
BASE\ORACLE_HOME\bin directory. All other components are located in the
ORACLE_BASE\ORACLE_HOME\com\java directory.
System Requirements
Note the following system requirements.
■ Oracle COM Automation Feature requires:
■ Windows XP, Windows 2000, or Windows Server 2003
■ A functioning database on the computer before installation takes place
■ Any COM Automation Server: For example, the COM Automation Feature
demonstrations require that you first install the applications that are used in the
demonstration programs.
■ The Microsoft Word, Excel, and PowerPoint demos require Microsoft Office
2000 or higher.
■ The Messaging Application Programming Interface (MAPI) demo requires
Microsoft Outlook 2000 or higher.
The demonstrations and installations are discussed in "Overview of PL/SQL
Demos" on page 4-1 and "Oracle COM Automation Feature Java Demos
Overview" on page 5-1.
3. Grant the CREATE LIBRARY privilege to the database users who will use Oracle
COM Automation Feature. For example:
SQL> GRANT CREATE LIBRARY TO hr;
4. Connect to the user who will use Oracle COM Automation Feature, and run the
comwrap.sql script at the SQL*Plus prompt:
SQL> CONNECT hr/hr;
SQL> @ORACLE_BASE\ORACLE_HOME\com\comwrap.sql
2. Run grant.sql with the name of the user who will be using COM Automation.
You may need to capitalize all the letters in the user's name. For example:
SQL> @ORACLE_BASE\ORACLE_HOME\com\java\grant.sql HR
ORACLE_BASE\ORACLE_HOME\com\java\orawcom.jar
In the preceding command, hr is the user who uses Oracle COM Automation
Feature.
)
)
Problem 1
Problem: The listener is not started.
Action: You must start the OracleHOME_NAMETNSListener service from the
Control Panel or the command prompt.
To start Oracle services from the Control Panel:
1. Choose Start, Settings, and then Control Panel.
The Control Panel window appears.
2. Double-click Services.
The Services dialog box appears.
3. Navigate to OracleHOME_NAMETNSListener in the list and verify that it has a
status of Started. If it does not, select it and click Start.
To start Oracle services from the command prompt:
Enter the following command to start an Oracle service at the command prompt:
C:\> net start service
Problem 2
Problem: The listener is not configured correctly.
Action: You must modify the listener.ora and tnsnames.ora files.
See Also: "Configuring the Listener for PL/SQL" on page 2-4 for
information on how to configure these files
Automation Feature. It is essential that you configure the DCOM security properly
and provide the Oracle Database with the necessary permissions.
This chapter describes aspects of the programming interface for Oracle COM
Automation Feature.
This chapter contains these topics:
■ Datatype Conversions
■ HRESULT Error Codes
■ Oracle COM Automation for Java Exception Handling
■ Typical COM Automation Functionality
■ Application Programming Interfaces
■ PL/SQL APIs
■ Java APIs
Datatype Conversions
Because Microsoft COM Automation uses COM Automation datatypes, and Oracle
COM Automation Feature uses either PL/SQL or Java datatypes, Oracle COM
Automation Feature must convert the data that it receives and pass it to the COM
Automation object. Similarly, Oracle COM Automation Feature must pass the data that
it receives from the COM Automation object and convert it.
Note: The HRESULT data member has the same meaning as the
value of HRESULT returned by the PL/SQL functions.
Code Sample
This example demonstrates the COMException exception.
try
{
// Some code which might throw a COMException exception.
}
catch(COMException e)
{
System.out.println(e.toString());
if(e.excepInfo)
{
System.out.println(e.source);
System.out.println(e.description);
System.out.println(e.helpfile);
System.out.println(e.helpid);
}
}
Use the progID with the API that instantiates the COM object.
■ You must be aware of the types of properties and methods that are exposed
through the COM object's IDispatch interface. Usually, the ISV provides
documentation describing the names and datatype of the object's properties and
the prototypes of the object's methods. Properties are referred to by a descriptive
string, such as xpos or ypos. A property can be any standard COM Automation
datatype, such as INT or BSTR. The GetProperty and SetProperty APIs take
the property name and a variable of the appropriate datatype. Methods are
referred to by a descriptive string, such as InsertChart. A method takes a set of
parameters that are of different COM Automation datatypes and returns a COM
Automation datatype.
The following is an example of a COM Automation method prototype in COM
Interface Definition Language (IDL) grammar:
[id(0x6003000)]
long Post([in, out] long* lngAccountNo,
[in, out] long* lngAmount,
[in, out] BSTR* strResult);
Interfaces define object methods and properties. COM IDL is used to specify
interfaces that are defined on COM objects.
As part of preparation for the Invoke API call, you use InitArg and SetArg in
Java and you use InitArg and SetArg in PL/SQL to package the argument to be
sent to the COM Automation method.
4. Calls GetLastError in PL/SQL to get the most recent error information
5. Destroys the object using DestroyObject in PL/SQL or Destroy in Java
PL/SQL APIs
The feature externalizes the following APIs for PL/SQL development:
■ CreateObject
■ DestroyObject
■ GetLastError
■ GetProperty
■ SetProperty
■ InitArg
■ InitOutArg
■ GetArg
■ SetArg
■ Invoke
Java APIs
The COM Automation Feature externalizes the following APIs for Java development:
■ Automation Constructor
■ Automation Methods
■ Create
■ Destroy
■ GetProperty
■ SetProperty
■ InitArg
■ SetArg
■ Invoke
■ Currency Constructor
■ Currency Methods
■ Get
■ Set
PL/SQL APIs
This section describes the PL/SQL APIs for manipulating COM objects using the COM
Automation interface. Each of the following PL/SQL stored procedures resides in the
package ORDCOM.
CreateObject
This API instantiates a COM object in a COM Automation server.
Syntax
FUNCTION CreateObject(progid VARCHAR2, reserved BINARY_INTEGER, servername
VARCHAR2, objecttoken OUT BINARY_INTEGER) RETURN BINARY_INTEGER;
Where Is
progid the programmatic identifier (progID) of the COM Automation
object to create. This character string describes the class of the
COM Automation object and has the following form:
COMComponent.Object
COMComponent is the component name of the COM
Automation server, and Object is the name of the COM
Automation object. The specified COM Automation object must
be creatable and must support the IDispatch interface.
reserved a parameter currently reserved for future use. Pass a value of 0.
Future versions of Oracle COM Automation Feature may use
this parameter.
servername the name of the remote DCOM server on which the COM object
is being instantiated.
Passing a specified name forces Oracle COM Automation
Feature to attempt to instantiate the COM object on a remote
computer. Passing an empty string, for example, '', forces Oracle
COM Automation Feature to check the registry for the location
of the COM object. Registry information indicates whether the
COM object is local or remote. Therefore, to create a local COM
object, always pass an empty string and ensure that the registry
indicates that the COM object exists locally. The registry
information for COM objects can be configured with the tool
dcomcnfg.exe.
objecttoken the returned object token. It must be a local variable of datatype
BINARY_INTEGER. This object token identifies the created COM
Automation object and is used in calls to the other Oracle COM
Automation Feature APIs.
Remarks
The created COM Automation object is 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.
This procedure returns 0 when successful, or a nonzero value for HRESULT when an
error occurs.
Code Sample
HRESULT BINARY_INTEGER;
applicationToken BINARY_INTEGER:=-1;
DestroyObject
This API destroys a created COM Automation object.
Syntax
FUNCTION DestroyObject(objecttoken BINARY_INTEGER) RETURN BINARY_INTEGER;
Where Is
objecttoken the object token of a COM Automation object previously created
by CreateObject.
Remarks
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 0 when successful, or a nonzero value of HRESULT when an
error occurs.
Code Sample
HRESULT BINARY_INTEGER;
applicationToken BINARY_INTEGER:=-1;
HRESULT:=ORDCOM.DestroyObject(applicationToken);
IF (HRESULT!=0) THEN
dbms_output.put_line(HRESULT);
GetLastError
This API obtains the COM Automation error information about the last error that
occurred.
Syntax
FUNCTION GetLastError(source OUT VARCHAR2, description OUT VARCHAR2, helpfile OUT
VARCHAR2, helpid OUT BINARY_INTEGER) RETURN BINARY_INTEGER;
Where Is
source the source of the error information. If specified, it must be a local
CHAR or VARCHAR variable. The return value is truncated to fit
the local variable if necessary.
description the description of the error. If specified, it must be a local CHAR
or VARCHAR variable. The return value is truncated to fit the
local variable if necessary.
Where Is
helpfile the Help file for the COM Automation object. If specified, it
must be a local CHAR or VARCHAR variable. The return value is
truncated to fit the local variable if necessary.
helpid the Help file context ID. If specified, it must be a local INT
variable.
Remarks
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 0 when successful, or a nonzero value of HRESULT when an
error occurs.
See "Microsoft COM Automation Errors" on page A-3 for a description of the types of
errors that can be returned by this function.
Code Sample
HRESULT BINARY_INTEGER;
applicationToken BINARY_INTEGER:=-1;
error_src VARCHAR2(255);
error_description VARCHAR2(255);
error_helpfile VARCHAR2(255);
error_helpID BINARY_INTEGER;
dbms_output.put_line(error_helpfile);
END IF;
GetProperty
This API gets a property value of a COM Automation object.
Syntax
FUNCTION GetProperty(objecttoken BINARY_INTEGER, propertyname VARCHAR2, argcount
BINARY_INTEGER, propertyvalue OUT any_PL/SQL_datatype) RETURN BINARY_INTEGER;
Where Is
objecttoken the object token of a COM object previously created by
CreateObject.
propertyname the property name of the COM object to return.
argcount the index of the property array. If the property is not an array,
then the developer should specify 0.
Where Is
propertyvalue the returned property value. The returned property type
depends on the COM Automation datatype that is returned. You
must pass the PL/SQL datatype that corresponds to the COM
Automation datatype of the COM Automation property.
Otherwise, the COM Automation Feature will not properly
convert the COM Automation datatype.
any_PL/SQL_ any datatype supported by COM Automation Feature.
datatype
Remarks
If the property returns a COM object, then you must specify a local variable of
datatype BINARY_INTEGER for the propertyvalue parameter. An object token is
stored in the local variable, and this object token can be used with other COM
Automation stored procedures.
When the property returns an array, if propertyvalue is specified, then it is set to
NULL.
This procedure returns 0 when successful, or a nonzero value of HRESULT when an
error occurs.
Code Sample
/*
* This is an excerpt from a Microsoft Excel application.
*/
HRESULT BINARY_INTEGER;
ChartObject BINARY_INTEGER := -1;
ChartToken BINARY_INTEGER := -1;
SetProperty
This API sets a property of a COM Automation object to a new value.
Syntax
FUNCTION SetProperty(objecttoken BINARY_INTEGER, propertyname VARCHAR2, newvalue
any_PL/SQL_datatype, datatype VARCHAR2) RETURN BINARY_INTEGER;
Where Is
objecttoken the object token of a COM Automation object previously created
by CreateObject.
propertyname the property name of the COM object to set to a new value.
newvalue the new value of the property. It must be a value of the
appropriate datatype.
Where Is
datatype the explicitly specified datatype of the value passed in. The
available datatypes are:
■ UI1 - byte integer
■ I2 - 2 byte integer
■ I4 - 4 byte integer
■ R4 - IEEE 4 byte real
■ R8 - IEEE 8 byte real
■ SCODE - error code
■ CY - currency (value - 9999999999.9999 to 9999999999.9999)
(This is an Oracle restriction)
■ DISPATCH - dispatch pointer
■ BSTR - String
■ BOOL - boolean
■ DATE - date
any_PL/SQL_ any datatype supported by COM Automation Feature.
datatype
Remarks
This procedure returns a 0 when successful, or a nonzero value of HRESULT when an
error occurs.
Code Sample
/*
* This is an excerpt from a Microsoft Excel application.
*/
HRESULT BINARY_INTEGER;
RangeToken BINARY_INTEGER := -1;
InitArg
This API initializes the parameter set passed to an Invoke call.
Syntax
PROCEDURE InitArg();
Remarks
The InitArg call initializes the parameter set. After InitArg has been called, a
SetArg call sets the first parameter to the specified value. A second SetArg 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 has been called after an
InitArg call. Another call to InitArg resets the argument list and a call to SetArg
sets the first parameter again.
Code Sample
See "Invoke" on page 3-15 for sample code.
InitOutArg
InitOutArg must be called after a COM method is invoked in preparation for getting
the values of OUT and IN OUT parameters using GetArg. After calling InitOutArg,
the first call to GetArg gets the value for the first OUT or IN OUT parameter, the second
call to GetArg gets the value for the second OUT or IN OUT parameters, and so on.
Calling InitOutArg again restarts this process.
Syntax
PROCEDURE InitOutArg();
Remarks
See the section on SetArg datatype strings in "SetArg" on page 3-21 for information
about IN and OUT parameters.
Code Sample
See "Invoke" on page 3-22 for sample code.
GetArg
Gets the argument of OUT and IN OUT parameters after the COM method has been
invoked.
Syntax
PROCEDURE GetArg(data OUT any_PL/SQL_datatype, type VARCHAR2);
Where Is
data the value of the OUT or IN OUT parameter after the COM method
has been invoked.
type the COM Automation datatype of the parameter.
Where Is
The available datatypes are:
■ pUI1 - byte integer
■ pI2 - 2 byte integer
■ pI4 - 4 byte integer
■ pR4 - IEEE 4 byte real
■ pR8 - IEEE 8 byte real
■ pSCODE - error code
■ pCY - currency (value -9999999999.9999 to 9999999999.9999)
(This is an Oracle restriction)
■ pDISPATCH - dispatch pointer
■ pBSTR - String
■ pBOOL - Boolean
■ pDATE - date
any_PL/SQL_ any datatype supported by COM Automation Feature.
datatype
Remarks
See the section on SetArg datatype strings in "SetArg" on page 3-21 for information
about IN and OUT parameters.
Code Sample
See "Invoke" on page 3-22 for sample code.
SetArg
Used to construct the parameter list for the next Invoke call.
SetArg sets a parameter's value to be passed by value.
Syntax
PROCEDURE SetArg(paramvalue any_PL/SQL_datatype, datatype VARCHAR2);
Where Is
paramvalue the value of the parameter to be passed to an Invoke call. The
parameter set is the nth parameter in the parameter list, where n
is the number of times SetArg has been called after an
InitArg call.
datatype the explicitly specified datatype for the parameters.
Those datatypes prefaced by an initial p are IN OUT or OUT
parameters. The p indicates that the VT_BYREF flag will be set
for the COM Automation datatype.
Where Is
Those datatypes without the initial p are IN parameters. The
available datatypes are:
■ UI1 - byte integer
■ pUI1 - byte integer
■ I2 - 2 byte integer
■ pI2 - 2 byte integer
■ I4 - 4 byte integer
■ pI4 - 4 byte integer
■ R4 - IEEE 4 byte real
■ pR4 - IEEE 4 byte real
■ R8 - IEEE 8 byte real
■ pR8 - IEEE 8 byte real
■ SCODE - error code
■ pSCODE - error code
■ CY - currency (value -9999999999.9999 to 9999999999.9999)
(This is an Oracle restriction)
■ pCY - currency (value -9999999999.9999 to 9999999999.9999)
(This is an Oracle restriction)
■ DISPATCH - dispatch pointer
■ pDISPATCH - dispatch pointer
■ BSTR - String
■ pBSTR - String
■ BOOL - Boolean
■ pBOOL - Boolean
■ DATE - date
■ pDATE - date
any_PL/SQL_ any datatype supported by COM Automation Feature.
datatype
Remarks
Each SetArg procedure sets the nth parameter value. The InitArg call initializes the
parameter set. After InitArg has been called, a SetArg call sets the first parameter to
the specified value. A second SetArg 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 has been called after an InitArg call. Another call to
InitArg resets the argument list and a call to SetArg sets the first parameter again.
Datatypes without the initial p are IN parameters. Those datatypes prefaced by an
initial p are IN OUT or OUT parameters.
Code Sample
See "Invoke" on page 3-15 for sample code.
Invoke
This API calls a method of a COM Automation object. This function uses the
parameter list, previously created by the calls to InitArg and SetArg as input for the
COM Automation method.
Syntax
FUNCTION Invoke(objecttoken BINARY_INTEGER, methodname VARCHAR2, argcount BINARY_
INTEGER, returnvalue OUT any_PL/SQL_datatype) RETURN BINARY_INTEGER;
Where Is
objecttoken the object token of a COM Automation object previously created
by CreateObject.
methodname the method name of the COM Automation object to call.
argcount the number of arguments passed to the COM Automation object
method.
returnvalue the return value of the method of the COM Automation object. If
specified, it must be a local variable of the appropriate datatype.
any_PL/SQL_ any datatype supported by COM Automation Feature.
datatype
Remarks
If the method's return value is a COM 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 0 when successful, or a nonzero value of HRESULT when an
error occurs.
Code Sample
/*
* Following is the IDL definition of the COM Automation method
* being called:
*
* HRESULT TestOutArg([in, out] short *x1,
* [in] short x2,
* [out] short *x3,
* [out, retval] short *x4);
*/
ORDCOM.InitArg();
ORDCOM.SetArg(x1, 'pI2');
ORDCOM.SetArg(x2, 'I2');
ORDCOM.SetArg(x3, 'pI2');
ORDCOM.InitOutArg();
ORDCOM.GetArg(x1, 'pI2');
ORDCOM.GetArg(x3, 'pI2');
Java APIs
This section describes the Java APIs for manipulating COM objects using the COM
Automation interface. These APIs are found in the Automation and Currency Java
classes.
The Automation Java class provides access to COM objects that support COM
Automation. With this Java class, you can create a COM object and obtain a pointer to
the IDispatch interface for the COM object. You can then get and set properties on
the COM object, as well as invoke methods (with or without arguments) on the COM
object. This class provides a wrapper for the COM object, so there is no direct access to
the COM object or to its IDispatch interface.
The Currency Java class represents the CURRENCY COM Automation datatype.
CURRENCY is a an 8-byte number where the last four digits represent the fractional
part of the value. For example, the number 12345 actually represents the value 1.2345.
CURRENCY has a range of (+/-)922337203685477.5807.
Note: Oracle COM Automation Feature for Java does not allow
in-process COM Automation servers. Developers can use dllhost
to support in-process servers.
Automation Constructor
This API creates a COM object.
Syntax
public Automation()
public Automation(String progID)
public Automation(String progID, String serverName)
Where Is
progid the programmatic identifier (progID) of the COM Automation
object to create. This character string describes the class of the
COM Automation object and has the following form:
COMComponent.Object
COMComponent is the component name of the COM
Automation server, and Object is the name of the COM
Automation object. The specified COM Automation object must
be creatable and must support the IDispatch interface.
servername the name of the remote DCOM server on which the COM object
is being instantiated.
Passing a specified name forces Oracle COM Automation
Feature to attempt to instantiate the COM object on a remote
computer.
Remarks
The default constructor public Automation() does nothing. It is used with a
Create method.
Using a constructor that takes only the progid parameter forces Oracle COM
Automation Feature to check the registry for the location of the COM object. Registry
information indicates whether the COM object is local or remote.
COM Automation objects created using the nondefault constructors are freed with a
corresponding call to Destroy. This nullifies the internal representation of the objects in
Oracle COM Automation Feature and releases all the interfaces associated with the
objects.
Oracle COM Automation Feature for Java does not allow in-process COM Automation
servers. Developers can use dllhost to support in-process servers.
The COMException exception is thrown if an error occurs.
Code Sample
The following code sample demonstrates the nondefault constructors.
"\\ServerMachineName");
Create
This API instantiates a COM object in a COM Automation server.
Syntax
public void Create(String progID)
public void Create(String progID, String serverName)
Where Is
progid the programmatic identifier (progID) of the COM Automation
object to create. This character string describes the class of the
COM Automation object and has the following form:
COMComponent.Object
COMComponent is the component name of the COM
Automation server, and Object is the name of the COM
Automation object. The specified COM Automation object must
be creatable and must support the IDispatch interface.
servername the name of the remote DCOM server on which the COM object
is being instantiated.
Passing a specified name forces Oracle COM Automation
Feature to attempt to instantiate the COM object on a remote
computer.
Remarks
The COM Automation object created with the Create method is freed with a
corresponding call to Destroy. This nullifies the internal representation of the object
in Oracle COM Automation Feature and releases all the interfaces associated with the
object.
Using the constructor that takes only the progid parameter forces Oracle COM
Automation Feature to check the registry for the location of the COM object. Registry
information indicates whether the COM object is local or remote.
Oracle COM Automation Feature for Java does not allow in-process COM Automation
servers. Developers can use dllhost to support in-process servers.
The COMException exception is thrown if an error occurs.
Code Sample
// Use the default constructor.
Automation word = new Automation();
Automation excel = new Automation();
Destroy
This API destroys a created COM Automation object.
Syntax
public void Destroy()
Remarks
Calling Destroy nullifies the internal representation of the object in the Oracle COM
Automation Feature and releases all the interfaces associated with the object.
Code Sample
See "Create" on page 3-18 for code sample.
GetProperty
This API gets a property value of a COM Automation object.
Syntax
public allowed_type GetProperty(String propName, allowed_type[] propVal)
Where Is
propName the property name of the COM object to return
propVal the returned property value. The returned property type
depends on the COM Automation type that is returned. The
array must be big enough to hold at least one element although
only the first element will be accessed to return the property.
allowed_type from the following list:
■ boolean
■ byte
■ char
■ short
■ int
■ long
■ float
■ double
■ java.long.String
■ oracle.win.com.Automation
■ oracle.win.com.Currency
■ java.util.Calendar
Remarks
If the property is a COM object, then it can be retrieved using the allowed_type of
oracle.win.com.Automation. The Automation Java object that is returned can be
used to get and set properties and call methods on the property.
GetProperty uses an array parameter to return the property value to overload the
GetProperty method. Overloading would not be possible if the property value were
returned as a return value. The array solves the problem caused by Java not having an
out parameter.
The property is still returned as a return value for convenience.
The COMException exception is thrown if an error occurs.
Code Sample
SetProperty
This API sets a property of a COM Automation object to a new value.
Syntax
public void SetProperty(String propName, allowed_type propVal)
Where Is
propName the property name of the COM object being set to a new value
propVal the new value of the property. It must be a value of the
appropriate datatype.
allowed_type from the following list:
Where Is
■ boolean
■ byte
■ char
■ short
■ int
■ long
■ float
■ double
■ java.long.String
■ oracle.win.com.Automation
■ oracle.win.com.Currency
■ java.util.Calendar
Remarks
If the property is a COM object, it can be set using the allowed type of
oracle.win.com.Automation. The property value must be a valid Automation
Java object.
The COMException exception is thrown if an error occurs.
Code Sample
See "GetProperty" on page 3-19 for sample code.
InitArg
This API initializes the parameter set passed to an Invoke call.
Syntax
public void InitArg()
Remarks
The InitArg call initializes the parameter set and must be called even if the COM
method does not take any parameters. After InitArg has been called, a SetArg call
sets the first parameter to the specified value. A second SetArg 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 has been called after an
InitArg call. Another call to InitArg resets the argument list and a call to SetArg
sets the first parameter again.
Code Sample
See "Invoke" on page 3-22 for sample code.
SetArg
This API is used to construct the parameter list for the next Invoke call.
Syntax
public void SetArg(allowed_type val)
Where Is
val the value of the parameter to be passed to an Invoke call. The
parameter set is the nth parameter in the parameter list, where n
is the number of times SetArg has been called after an
InitArg call.
allowed_type from the following list.
■ boolean
■ byte
■ char
■ short
■ int
■ long
■ float
■ double
■ java.long.String
■ oracle.win.com.Automation
■ oracle.win.com.Currency
■ java.util.Calendar
Remarks
If a parameter is a COM object, then the allowed_type of the corresponding
argument should be oracle.win.com.Automation. The argument should be a
valid Automation Java object.
No exceptions are thrown at this time. However, if an error occurs, for example, if the
wrong argument type is passed, then it will be caught when the Invoke method is
called.
Code Sample
See "Invoke" on page 3-22 for sample code.
Invoke
Calls a method of a COM Automation object. This function uses the parameter list,
previously created by the calls to InitArg and SetArg, as input for the COM
Automation method.
Syntax
public void Invoke(String methodName, allowed_type[] retVal)
public void Invoke(String methodName)
Where Is
methodName the method name of the COM Automation object to call
retVal the return value of the method of the COM Automation object. If
specified, then it must be a local variable of the appropriate
datatype. The array must be big enough to hold at least one
element, although only the first element will be accessed to
return the property.
Where Is
allowed_type a type from the following list:
■ boolean
■ byte
■ char
■ short
■ int
■ long
■ float
■ double
■ java.long.String
■ oracle.win.com.Automation
■ oracle.win.com.Currency
■ java.util.Calendar
Remarks
If the COM method returns a COM object as the return value, then the allowed_
type of the return value is oracle.win.com.Automation. The Automation Java
object that is returned can be used to get and set properties, and call methods on the
return value.
To overload the Invoke method, Invoke uses an array parameter to return the
values of COM object methods. Overloading would not be possible if the property
value was returned as a return value. The array solves the problem caused by Java not
having an out parameter.
The version of Invoke that takes only one parameter, public void
Invoke(String methodName), is used for COM object methods with void return
types.
The property is still returned as a return value for convenience.
The COMException exception is thrown if an error occurs.
Code Sample
// A Microsoft Excel Worksheet object.
Automation workSheet = null;
// A Microsoft Excel ChartObjects collection object.
Automation chartObjects = null;
// A Microsoft Excel ChartObject object.
Automation chartObject = null;
// Used for return values of type Automation.
Automation[] autorv = { null };
// Dimensions for a Microsoft Excel ChartObject object.
short xpos = 100, ypos = 30, width = 400, height = 250;
chartObjects.InitArg();
chartObjects.SetArg(xpos);
chartObjects.SetArg(ypos);
chartObjects.SetArg(width);
chartObjects.SetArg(height);
chartObjects.Invoke("Add", autorv);
chartObject = autorv[0];
Currency Constructor
This API creates a currency Java object.
Syntax
public Currency(long value)
Where Is
value the 8-byte CURRENCY number
Get
This API gets the 8-byte CURRENCY number.
Syntax
public long Get()
Remarks
Returns the 8-byte CURRENCY number.
Set
This API sets the 8-byte CURRENCY number.
Syntax
public void Set(long value)
Where Is
value the 8-byte CURRENCY number
This chapter describes how to use Oracle COM Automation Feature demonstration
programs for PL/SQL.
This chapter contains these topics:
■ Overview of PL/SQL Demos
■ Microsoft Word Demo
■ Microsoft Excel Demo
■ Microsoft PowerPoint Demo
■ MAPI Demo
The demo creates a Microsoft Word document containing the names of employees in
the database.
The Microsoft Word demo provides the following:
■ ORDWord, a PL/SQL package that exposes several APIs for manipulating
Microsoft Word. This package is created by the wordsol.sql script.
■ worddem.sql, a script that displays the capabilities of exchanging data between
Oracle and Microsoft Word. It exchanges data from the EMPLOYEES and JOBS
tables to a Microsoft Word document. These tables are available in the human
resources schema in the sample schema.
2. Connect to the Oracle database instance as the user who will use the Microsoft
Word demo. For example:
SQL> connect hr/hr
This script creates the ORDWord package in the current user's schema. You receive
the following error several times when you run this script for the first time:
ORA-04043: object XXXX does not exist.
Core Functionality
The following subsections describe the APIs that the Microsoft Word demo exposes.
These APIs are primitive. Be aware that much of the functionality that Microsoft Word
exposes through COM Automation is not exposed through these APIs.
CreateWordObject
This API instantiates a Word.Basic object in the Microsoft Word Automation server.
Syntax
FUNCTION CreateWordObject() RETURN BINARY_INTEGER;
Remarks
This function must be called before any other operation can be performed. This
procedure returns 0 when successful, or a nonzero value for HRESULT when an error
occurs.
FileNew
This API creates a new Microsoft Word document.
Syntax
FUNCTION FileNew() RETURN BINARY_INTEGER;
Remarks
This procedure returns 0 when successful, or a nonzero value for HRESULT when an
error occurs.
FileLoad
This API loads a document into Microsoft Word.
Syntax
FUNCTION FileLoad(filename VARCHAR2) RETURN BINARY_INTEGER;
Where Is
filename the fully qualified filename of the document.
Remarks
This procedure returns a 0 when successful or a nonzero HRESULT when an error
occurs.
FileSave
This API saves the current Microsoft Word document to disk.
Syntax
FUNCTION FileSave() RETURN BINARY_INTEGER;
Remarks
This procedure returns 0 when successful, or a nonzero value for HRESULT when an
error occurs.
FileSaveAs
This API saves the current Microsoft Word document as a specific file.
Syntax
FUNCTION FileSaveAs(filename VARCHAR2) RETURN BINARY_INTEGER;
Where Is
filename the fully qualified filename of the document.
Remarks
This procedure returns 0 when successful, or a nonzero value for HRESULT when an
error occurs.
FileClose
This API closes the current Microsoft Word document.
Syntax
FUNCTION FileClose() RETURN BINARY_INTEGER;
Remarks
This procedure returns 0 when successful, or a nonzero value for HRESULT when an
error occurs.
InsertText
This API inserts a text string into the current Microsoft Word document.
Syntax
FUNCTION InsertText(textstr VARCHAR2) RETURN BINARY_INTEGER;
Where Is
textstr the text that will be inserted into the document.
Remarks
This procedure returns 0 when successful, or a nonzero value for HRESULT when an
error occurs.
InsertNewLine
This API inserts a carriage return into the current Microsoft Word document.
Syntax
FUNCTION InsertNewLine() RETURN BINARY_INTEGER;
Remarks
This procedure returns 0 when successful, or a nonzero value for HRESULT when an
error occurs.
FormatFontSize
This API sets the font size for the current Microsoft Word document.
Syntax
FUNCTION FormatFontSize(fontsize BINARY_INTEGER) RETURN BINARY_INTEGER;
Where Is
fontsize the point size of the font.
Remarks
This procedure returns 0 when successful, or a nonzero value for HRESULT when an
error occurs.
2. Connect to the Oracle database instance as the user who will use the Microsoft
Excel demo. For example:
SQL> connect hr/hr
This script creates the ORDExcel package in the schema of the current user. You
receive the following error several times when you run this script for the first time:
ORA-04043: object XXXX does not exist.
Core Functionality
The following subsections describe the APIs that the Microsoft Excel demo exposes.
These APIs are primitive. Be aware that much of the functionality that Microsoft Excel
exposes through COM Automation is not exposed through these APIs.
CreateExcelWorkSheet
Starts the Microsoft Excel COM Automation server and instantiates the objects for a
workbook and a worksheet.
Syntax
FUNCTION CreateExcelWorkSheet() RETURN BINARY_INTEGER;
Remarks
This procedure returns 0 when successful, or a nonzero value for HRESULT when an
error occurs.
InsertData
This API inserts any kind of data into a specific cell of the current Excel worksheet.
Syntax
FUNCTION InsertData(range VARCHAR2, data any_PL/SQL_datatype, datatype VARCHAR2)
RETURN BINARY_INTEGER;
Where Is
range a string that indicates a specific cell in the current Excel
worksheet (for example, 'A1', 'B1').
data the data that you want to insert into the current Excel worksheet.
datatype a string that indicates the datatype of the data that you are
inserting into Excel. The list of available datatypes are:
■ I2 - 2 byte integer
■ I4 - 4 byte integer
■ R4 - IEEE 4 byte real
■ R8 - IEEE 8 byte real
■ SCODE - error code
■ CY - currency
■ DISPATCH - dispatch pointer
■ BSTR - String
■ BOOL - boolean
■ DATE - date
any_PL/SQL_ any datatype supported by COM Automation Feature.
datatype
Remarks
This procedure returns 0 when successful, or a nonzero value for HRESULT when an
error occurs.
InsertChart
This API creates a chart of a specified range of data and inserts the chart at the x and y
position of the current worksheet with the desired height and width.
Syntax
FUNCTION InsertChart(xpos BINARY_INTEGER, ypos BINARY_INTEGER, width BINARY_
INTEGER, height BINARY_INTEGER, range VARCHAR2, type VARCHAR2) RETURN BINARY_
INTEGER;
Where Is
xpos the x position in the current worksheet where the chart should
be inserted
ypos the y position in the current worksheet where the chart should
be inserted
width the width of the chart
height the height of the chart
range the range of cells to be graphed
type the datatype of the data to be graphed
Remarks
This procedure returns 0 when successful, or a nonzero value for HRESULT when an
error occurs.
SaveExcelFile
This API saves the current Microsoft Excel workbook as a specific file.
Syntax
FUNCTION SaveExcelFile(filename VARCHAR2) RETURN BINARY_INTEGER;
Where Is
filename the fully qualified filename of the Excel workbook
Remarks
This procedure returns 0 when successful, or a nonzero value for HRESULT when an
error occurs.
ExitExcel
Performs some cleanup and destroys the outstanding references to the Excel COM
Automation server. This should be the last API called.
Syntax
FUNCTION ExitExcel() RETURN BINARY_INTEGER;
Remarks
This procedure returns a 0 when successful or a nonzero HRESULT when an error
occurs.
2. Connect to the Oracle database instance as the user who will use the Microsoft
PowerPoint demo. For example:
SQL> connect hr/hr
This script creates the ORDPPT package in the current user's schema. You receive
the following error several times when you run this script for the first time:
ORA-04043: object XXXX does not exist.
Core Functionality
The following subsections describe the APIs that the Microsoft PowerPoint demo
exposes. These APIs are primitive. Be aware that much of the functionality that
Microsoft PowerPoint exposes through COM Automation is not exposed through
these APIs.
CreatePresentation
This API starts the Microsoft PowerPoint COM Automation server and instantiates the
objects for a presentation.
Syntax
FUNCTION CreatePresentation (servername IN VARCHAR2) RETURN BINARY_INTEGER;
Remarks
This procedure returns 0 when successful, or a nonzero value for HRESULT when an
error occurs.
AddSlide
This API inserts a new slide in the PowerPoint presentation.
Syntax
FUNCTION AddSlide (layout IN BINARY_INTEGER) RETURN BINARY_INTEGER;
Remarks
This procedure returns 0 when successful, or a nonzero value for HRESULT when an
error occurs.
SetTitle
This API specifies the title of the PowerPoint slide.
Syntax
FUNCTION SetTitle (title IN VARCHAR2) RETURN BINARY_INTEGER;
Remarks
This procedure returns 0 when successful, or a nonzero value for HRESULT when an
error occurs.
InsertText
This API inserts text into the specified location on the slide.
Syntax
FUNCTION InsertText (orientation IN BINARY_INTEGER, left IN BINARY_INTEGER, top IN
BINARY_INTEGER, width IN BINARY_INTEGER, height IN BINARY_INTEGER, text IN
VARCHAR2) RETURN BINARY_INTEGER;
Remarks
This procedure returns 0 when successful, or a nonzero value for HRESULT when an
error occurs.
PresentationSave
This API saves the current PowerPoint presentation.
Syntax
FUNCTION PresentationSave RETURN BINARY_INTEGER;
Remarks
This procedure returns 0 when successful, or a nonzero value for HRESULT when an
error occurs.
PresentationSaveAs
This API saves the current presentation using the specified name.
Syntax
FUNCTION PresentationSaveAs (filename IN VARCHAR2) RETURN BINARY_INTEGER;
Remarks
This procedure returns 0 when successful, or a nonzero value for HRESULT when an
error occurs.
PresentationClose
This API closes the current PowerPoint presentation.
Syntax
FUNCTION PresentationClose RETURN binary_integer;
Remarks
This procedure returns 0 when successful, or a nonzero value for HRESULT when an
error occurs.
Exit
This API exits the PowerPoint program.
Syntax
FUNCTION Exit RETURN BINARY_INTEGER;
Remarks
This procedure returns 0 when successful, or a nonzero value for HRESULT when an
error occurs.
MAPI Demo
The following sections detail how to install the Messaging Application Programming
Interface (MAPI) demo and describe the APIs that it exposes. This demo is provided
as an example of the types of solutions that can be built with Oracle Database instance
and MAPI-compliant applications.
The MAPI demo provides the following:
■ ORDMAPI, a PL/SQL package that exposes several APIs for manipulating
Extended MAPI client.
■ mapidem.sql, a script that displays the capabilities of exchanging data between
Oracle and Extended MAPI client.
■ mapi.reg, a registration entry file that updates the registry settings.
1. Log on to Windows NT using your local user account or domain user account, for
example, DOMAIN-1\hr.
2. Start the MAPI server (for example, Microsoft Outlook) and configure the MAPI
profile for the Windows NT user DOMAIN-1\hr. Make sure that you are able to
send out e-mail using this profile.
3. Go to the Windows NT Control Panel/Services.
4. Shut down the OracleHOME_NAMETNSListener service.
5. Select the OracleHOME_NAMETNSListener service and click Startup.
6. Change the Log On As to This Account and fill in DOMAIN-1\hr.
7. Enter the password and confirm the password for DOMAIN-1\hr.
8. Restart the OracleHOME_NAMETNSListener service.
9. Shut down the Oracle Database service.
10. Select the Oracle Database service and click Startup.
11. Change Log On As to This Account and fill in DOMAIN-1\hr.
12. Enter the password and confirm the password for DOMAIN-1\hr.
2. Connect to the Oracle Database instance as the user who will use the MAPI demo.
For example:
SQL> connect hr/hr
This script creates the ORDMAPI package in the current user's schema. You receive
the following error several times when you run this script for the first time:
ORA-04043: object XXXX does not exist.
This script connects to a database server, extracts the data, and sends an e-mail to a
specified recipient.
Core Functionality
The following subsections describe the APIs that the MAPI demo exposes. These APIs
are primitive. Be aware that much of the functionality that MAPI exposes through
COM Automation is not exposed through these APIs.
CreateMAPISession
This API starts the MAPI COM Automation server and instantiates the objects for a
session.
Syntax
FUNCTION CreateMAPISession (servername IN VARCHAR2 DEFAULT '', profilename IN
VARCHAR2 DEFAULT NULL, password IN VARCHAR2 DEFAULT NULL) RETURN BINARY_INTEGER;
Remarks
This procedure returns 0 when successful, or a nonzero value for HRESULT when an
error occurs.
NewMessage
This API creates a new message.
Syntax
FUNCTION NewMessage RETURN BINARY_INTEGER;
Remarks
This procedure returns 0 when successful, or a nonzero value for HRESULT when an
error occurs.
AddRecipient
This API adds the e-mail address of a recipient. This is the address where the e-mail
message will be sent.
Syntax
FUNCTION AddRecipient (emailaddress VARCHAR2) RETURN BINARY_INTEGER;
Remarks
This procedure returns a 0 when successful or a nonzero HRESULT when an error
occurs.
SetSubject
This API specifies the subject of the e-mail message.
Syntax
FUNCTION SetSubject (subject VARCHAR2) RETURN BINARY_INTEGER;
Remarks
This procedure returns 0 when successful, or a nonzero value for HRESULT when an
error occurs.
SetBody
This API inserts the body text of the e-mail message.
Syntax
FUNCTION SetBody (messagetext VARCHAR2) RETURN BINARY_INTEGER;
Remarks
This procedure returns 0 when successful, or a nonzero value for HRESULT when an
error occurs.
SendMessage
This API sends the e-mail message to the specified recipients.
Syntax
FUNCTION SendMessage RETURN BINARY_INTEGER;
Remarks
This procedure returns 0 when successful, or a nonzero value for HRESULT when an
error occurs.
EndMAPISession
This API exits the MAPI session.
Syntax
FUNCTION EndMAPISession RETURN BINARY_INTEGER;
Remarks
This procedure returns 0 when successful, or a nonzero value for HRESULT when an
error occurs.
This chapter describes how to use the demonstration program designed for Oracle
COM Automation Feature for Java.
This chapter contains these topics:
■ Oracle COM Automation Feature Java Demos Overview
■ Microsoft Word Java Demo
2. Start SQL*Plus.
C:\> sqlplus /NOLOG
3. Connect to the Oracle database instance as the user who will use the Microsoft
Word demo. For example:
SQL> connect hr/hr
6. Call the FileClose method when you are finished with the document.
7. Call the DestroyWordObject method when you are finished with the
Word.Basic object.
Core Functionality
The following subsections describe the APIs that the Microsoft Word Java demo
exposes. These APIs are primitive. Be aware that much of the functionality that
Microsoft Word exposes through COM Automation is not exposed through these APIs.
TestWORD
This API is the constructor. It does nothing.
Syntax
public TestWORD()
CreateWordObject
Creates the Word.Basic COM object.
Syntax
public void CreateWordObject(java.lang.String servername)
Where Is
servername the server on which to create the COM object. Specify null or the
empty string for the local server.
DestroyWordObject
This API destroys the Word.Basic COM object.
Syntax
public void DestroyWordObject()
FileNew
This API creates a new Microsoft WORD document.
Syntax
public void FileNew()
Remarks
Wrapper for the FileNewDefault COM method of the Word.Basic COM object.
FileLoad
This API loads an existing Microsoft WORD document.
Syntax
public void FileLoad(java.lang.String filename)
Where Is
filename the name of the file to load.
Remarks
Wrapper for the FileOpen COM method of the Word.Basic COM object.
FormatFontSize
This API sets the font size.
Syntax
public void FormatFontSize(long fontsize)
Where Is
fontsize the new font size.
Remarks
Wrapper for the FormatFont COM method of the Word.Basic COM object.
InsertText
This API inserts text into the Microsoft Word document.
Syntax
public void InsertText(java.lang.String textstr)
Where Is
textstr the text to insert.
Remarks
Wrapper for the Insert COM method of the Word.Basic COM object.
InsertNewLine
This API inserts a newline into the Microsoft Word document.
Syntax
public void InsertNewLine()
Remarks
Wrapper for the InsertPara COM method of the Word.Basic COM object.
FileSaveAs
This API saves the Microsoft Word document using a specified name.
Syntax
public void FileSaveAs(java.lang.String filename)
Where Is
filename the name of the file.
Remarks
Wrapper for the FileSaveAs COM method of the Word.Basic COM object.
FileSave
This API saves the Microsoft Word document.
Syntax
public void FileSave()
Remarks
Wrapper for the FileSave COM method of the Word.Basic COM object.
FileClose
This API closes the Microsoft Word document, and exits Microsoft Word.
Syntax
public void FileClose()
Remarks
Wrapper for the FileClose and FileExit COM methods of the Word.Basic COM
object.
COM-0018: The requested member does not exist, or the call to Invoke tried to set
the value of a read-only property
Cause: The requested member does not exist, or the call to Invoke tried to set the
value of a read-only property.
Action: Make sure that the property value can be written to or the member exists.
COM-0020: One of the arguments in rgvarg could not be coerced to the specified
type
Cause: One of the arguments is not the type expected by the method or property,
and the argument cannot be coerced to the expected type.
Action: Make sure that the coerced arguments are of compatible datatypes.
external procedure
A function written in a third-generation language (3GL), such as C, and callable from
within PL/SQL or SQL as if it were a PL/SQL function or procedure
GUID
An identifier that uniquely identifies a COM object. GUID is an acronym for Globally
Unique Identifier
IID
A GUID that identifies a COM interface
listener
The server process that listens for and accepts incoming connection requests from
client applications. Oracle listener processes start up Oracle Database processes to
handle subsequent communications with the client
listener.ora
A configuration file that describes one or more Transparent Network Substrate (TNS)
listeners on a server
Glossary-1
Oracle COM Automation Feature
An Oracle feature that enables PL/SQL developers to programmatically manipulate
COM objects through the IDispatch COM Automation interface
Oracle Net
The Oracle client/server communication software that offers transparent operation to
Oracle tools or databases over any type of network protocol and operating system
PL/SQL
Oracle's procedural language extension to SQL
progID
A descriptive string that maps to a GUID
tnsnames.ora
A file that contains connect descriptors mapped to net service names. The file may be
maintained centrally or locally, for use by all or individual clients
Glossary-2
Index
Index-1
EXTPROC Java Components, 2-2
extproc.exe, 1-4 Java Currency constructor, 3-24
F L
features listener
new, xi configuring for Oracle COM Automation, 2-4
loadjava, 5-2
G
GetArg M
PL/SQL API, 3-12 MAPI
GetLastError demo script mapidem.sql, 4-10
PL/SQL API, 3-8 PL/SQL example, 4-10
GetProperty MAPI demo, 4-11
Java API, 3-19 Messaging Application Programming Interface. See
PL/SQL API, 3-9 MAPI
Globally Unique Identifier (GUID), 3-4 Microsoft Excel
grant.sql, 2-2, 2-3 demo script exceldem.sql, 4-5
PL/SQL example, 4-5
Microsoft Outlook, 4-11
H
Microsoft PowerPoint
HRESULT demo script pptdem.sql, 4-8
return codes, 3-2 PL/SQL example, 4-8
Microsoft Word
I demo script worddem.sql, 4-2
example, 4-1
IDispatch interface, 3-7, 3-16, 3-17 Microsoft Word Java Demo, 5-1
IDL, 3-4 Migration from Oracle8i to Oracle Database 10g, 2-3
InitArg Migration from Oracle9i to Oracle Database 10g, 2-2
Java API, 3-21
PL/SQL API, 3-11
InitOutArg O
PL/SQL API, 3-12 OLE/COM Object Viewer, 3-5
installation ORA-28575 error message, 2-5
Oracle COM Automation, 2-1 Oracle COM Automation
installing PL/SQL MAPI demo architecture, 1-3
preparation, 4-11 benefits, 1-2
Installing the Microsoft Word Java Demo, 5-2 components, 2-1
Interface Definition Language, 3-4 configuring, 2-3
Internet Explorer, 4-11 core functionality, 1-1
Invoke demos, 4-1
Java API, 3-22 installing, 2-1
PL/SQL API, 3-15 introduction, 1-1
Java demos, 5-1
J Oracle COM Automation Feature Developer’s
Guide, vii
Java orawcom.dll, 2-2
configuration, 2-3 orawcomVER.dll, 1-5, 2-2
Java API orawpcom.dll, 2-3
Automation, 3-17 orawpcomVER.dll, 1-4, 2-1, 2-3
Create, 3-18 ORDExcel
Currency, 3-24 PL/SQL package, 4-5
Destroy, 3-19 ORDMAPI
GetProperty, 3-19 PL/SQL package, 4-10
InitArg, 3-21 ORDPPT
Invoke, 3-22 PL/SQL package, 4-8
SetArg, 3-21 ORDWord
SetProperty, 3-20 PL/SQL package, 4-2
Java APIs, 3-16 Outlook Client, 4-11
Java Automation constructor, 3-17
Index-2
P
PL/SQL
configuration, 2-3
ORDExcel package, 4-5
ORDMAPI package, 4-10
ORDPPT package, 4-8
ORDWord package, 4-2
PL/SQL API
CreateObject, 3-7
DestroyObject, 3-8
GetArg, 3-12
GetLastError, 3-8
GetProperty, 3-9
InitArg, 3-11
InitOutArg, 3-12
Invoke, 3-15
SetArg, 3-13
SetProperty, 3-10
PL/SQL Architecture, 1-3
PL/SQL Components, 2-1
preparing to install, 4-11
progID
COM objects, 3-4
program ID
COM objects, 3-4
R
return codes
HRESULT, 3-2
S
sample schema, 4-1, 5-1
SERVEROUTPUT, 5-2
SetArg
Java API, 3-21
PL/SQL API, 3-13
SetProperty
Java API, 3-20
PL/SQL API, 3-10
system requirements
Oracle COM Automation, 2-2
T
TestWORD, 5-2
TestWORD.class, 5-1
TestWORD.java, 5-1
TestWORD.sql, 5-1, 5-2
troubleshooting
Oracle COM automation PL/SQL errors, A-1
U
Using the Microsoft Word Demo, 5-2
W
wordemoj.doc, 5-2
Index-3
Index-4