public final class OleAutomation
extends java.lang.Object
The OLE Document or ActiveX Control must support the IDispatch interface in order to provide
OleAutomation support. The additional functionality provided by the OLE Object is specified in
its IDL file. The additional methods can either be to get property values (getProperty
),
to set property values (setProperty
) or to invoke a method (invoke
or
invokeNoReply
). Arguments are passed around in the form of Variant
objects.
Here is a sample IDL fragment:
interface IMyControl : IDispatch { [propget, id(0)] HRESULT maxFileCount([retval, out] int *c); [propput, id(0)] HRESULT maxFileCount([in] int c); [id(1)] HRESULT AddFile([in] BSTR fileName); };
An example of how to interact with this extended functionality is shown below:
OleAutomation automation = new OleAutomation(myControlSite);
// Look up the ID of the maxFileCount parameter
int[] rgdispid = automation.getIDsOfNames(new String[]{"maxFileCount"});
int maxFileCountID = rgdispid[0];
// Set the property maxFileCount to 100:
if (automation.setProperty(maxFileCountID, new Variant(100))) {
System.out.println("Max File Count was successfully set.");
}
// Get the new value of the maxFileCount parameter:
Variant pVarResult = automation.getProperty(maxFileCountID);
if (pVarResult != null) {
System.out.println("Max File Count is "+pVarResult.getInt());
}
// Invoke the AddFile method
// Look up the IDs of the AddFile method and its parameter
rgdispid = automation.getIDsOfNames(new String[]{"AddFile", "fileName"});
int dispIdMember = rgdispid[0];
int[] rgdispidNamedArgs = new int[] {rgdispid[1]};
// Convert arguments to Variant objects
Variant[] rgvarg = new Variant[1];
String fileName = "C:\\testfile";
rgvarg[0] = new Variant(fileName);
// Call the method
Variant pVarResult = automation.invoke(dispIdMember, rgvarg, rgdispidNamedArgs);
// Check the return value
if (pVarResult == null || pVarResult.getInt() != OLE.S_OK){
System.out.println("Failed to add file "+fileName);
}
automation.dispose();
Modifier and Type | Field and Description |
---|---|
private java.lang.String |
exceptionDescription |
private IDispatch |
objIDispatch |
private ITypeInfo |
objITypeInfo |
private IUnknown |
objIUnknown |
Constructor and Description |
---|
OleAutomation(IDispatch idispatch) |
OleAutomation(OleClientSite clientSite)
Creates an OleAutomation object for the specified client.
|
OleAutomation(java.lang.String progId)
Creates an OleAutomation object for the specified
progID . |
Modifier and Type | Method and Description |
---|---|
void |
dispose()
Disposes the automation object.
|
boolean |
equals(java.lang.Object object) |
(package private) int |
getAddress() |
(package private) GUID |
getClassID(java.lang.String clientName) |
java.lang.String |
getDocumentation(int dispId)
Returns the documentation string for the given member ID.
|
OleFunctionDescription |
getFunctionDescription(int index)
Returns the description of a function at the given index.
|
java.lang.String |
getHelpFile(int dispId)
Returns the fully qualified name of the Help file for the given member ID.
|
int[] |
getIDsOfNames(java.lang.String[] names)
Returns the positive integer values (IDs) that are associated with the specified names by the
IDispatch implementor.
|
java.lang.String |
getLastError()
Returns a description of the last error encountered.
|
java.lang.String |
getName(int dispId)
Returns the name of the given member ID.
|
java.lang.String[] |
getNames(int dispId,
int maxSize)
Returns the name of a function and parameter names for the specified function ID.
|
Variant |
getProperty(int dispIdMember)
Returns the value of the property specified by the dispIdMember.
|
Variant |
getProperty(int dispIdMember,
Variant[] rgvarg)
Returns the value of the property specified by the dispIdMember.
|
Variant |
getProperty(int dispIdMember,
Variant[] rgvarg,
int[] rgdispidNamedArgs)
Returns the value of the property specified by the dispIdMember.
|
OlePropertyDescription |
getPropertyDescription(int index)
Returns the property description of a variable at the given index.
|
TYPEATTR |
getTypeInfoAttributes()
Returns the type info of the current object referenced by the automation.
|
Variant |
invoke(int dispIdMember)
Invokes a method on the OLE Object; the method has no parameters.
|
private int |
invoke(int dispIdMember,
int wFlags,
Variant[] rgvarg,
int[] rgdispidNamedArgs,
Variant pVarResult) |
Variant |
invoke(int dispIdMember,
Variant[] rgvarg)
Invokes a method on the OLE Object; the method has no optional parameters.
|
Variant |
invoke(int dispIdMember,
Variant[] rgvarg,
int[] rgdispidNamedArgs)
Invokes a method on the OLE Object; the method has optional parameters.
|
void |
invokeNoReply(int dispIdMember)
Invokes a method on the OLE Object; the method has no parameters.
|
void |
invokeNoReply(int dispIdMember,
Variant[] rgvarg)
Invokes a method on the OLE Object; the method has no optional parameters.
|
void |
invokeNoReply(int dispIdMember,
Variant[] rgvarg,
int[] rgdispidNamedArgs)
Invokes a method on the OLE Object; the method has optional parameters.
|
private void |
manageExcepinfo(int hResult,
EXCEPINFO excepInfo) |
boolean |
setProperty(int dispIdMember,
Variant rgvarg)
Sets the property specified by the dispIdMember to a new value.
|
boolean |
setProperty(int dispIdMember,
Variant[] rgvarg)
Sets the property specified by the dispIdMember to a new value.
|
private IUnknown objIUnknown
private IDispatch objIDispatch
private java.lang.String exceptionDescription
private ITypeInfo objITypeInfo
OleAutomation(IDispatch idispatch)
public OleAutomation(OleClientSite clientSite)
clientSite
- the site for the OLE Document or ActiveX Control whose additional functionality
you need to accessjava.lang.IllegalArgumentException
- public OleAutomation(java.lang.String progId)
progID
.progId
- the unique program identifier of an OLE Document application;
the value of the ProgID key or the value of the VersionIndependentProgID key specified
in the registry for the desired OLE Document (for example, the VersionIndependentProgID
for Word is Word.Document)SWTException
- public void dispose()
This method releases the IDispatch interface on the OLE Document or ActiveX Control. Do not use the OleAutomation object after it has been disposed.
int getAddress()
GUID getClassID(java.lang.String clientName)
public java.lang.String getHelpFile(int dispId)
dispId
- the member ID whose Help file is being retrieved.public java.lang.String getDocumentation(int dispId)
dispId
- the member ID in which the documentation is being retrieved.public OlePropertyDescription getPropertyDescription(int index)
index
- the index of a variable whose property is being retrieved.public OleFunctionDescription getFunctionDescription(int index)
index
- the index of a function whose property is being retrieved.public TYPEATTR getTypeInfoAttributes()
public java.lang.String getName(int dispId)
dispId
- the member ID in which the name is being retrieved.public java.lang.String[] getNames(int dispId, int maxSize)
dispId
- the function ID in which the name and parameters are being retrieved.maxSize
- the maximum number of names to retrieve.public int[] getIDsOfNames(java.lang.String[] names)
names
- an array of names for which you require the identifierspublic java.lang.String getLastError()
public Variant getProperty(int dispIdMember)
dispIdMember
- the ID of the property as specified by the IDL of the ActiveX Control; the
value for the ID can be obtained using OleAutomation.getIDsOfNamespublic Variant getProperty(int dispIdMember, Variant[] rgvarg)
dispIdMember
- the ID of the property as specified by the IDL of the ActiveX Control; the
value for the ID can be obtained using OleAutomation.getIDsOfNamesrgvarg
- an array of arguments for the method. All arguments are considered to be
read only unless the Variant is a By Reference Variant type.public Variant getProperty(int dispIdMember, Variant[] rgvarg, int[] rgdispidNamedArgs)
dispIdMember
- the ID of the property as specified by the IDL of the ActiveX Control; the
value for the ID can be obtained using OleAutomation.getIDsOfNamesrgvarg
- an array of arguments for the method. All arguments are considered to be
read only unless the Variant is a By Reference Variant type.rgdispidNamedArgs
- an array of identifiers for the arguments specified in rgvarg; the
parameter IDs must be in the same order as their corresponding values;
all arguments must have an identifier - identifiers can be obtained using
OleAutomation.getIDsOfNamespublic boolean equals(java.lang.Object object)
equals
in class java.lang.Object
public Variant invoke(int dispIdMember)
dispIdMember
- the ID of the method as specified by the IDL of the ActiveX Control; the
value for the ID can be obtained using OleAutomation.getIDsOfNamespublic Variant invoke(int dispIdMember, Variant[] rgvarg)
dispIdMember
- the ID of the method as specified by the IDL of the ActiveX Control; the
value for the ID can be obtained using OleAutomation.getIDsOfNamesrgvarg
- an array of arguments for the method. All arguments are considered to be
read only unless the Variant is a By Reference Variant type.public Variant invoke(int dispIdMember, Variant[] rgvarg, int[] rgdispidNamedArgs)
dispIdMember
- the ID of the method as specified by the IDL of the ActiveX Control; the
value for the ID can be obtained using OleAutomation.getIDsOfNamesrgvarg
- an array of arguments for the method. All arguments are considered to be
read only unless the Variant is a By Reference Variant type.rgdispidNamedArgs
- an array of identifiers for the arguments specified in rgvarg; the
parameter IDs must be in the same order as their corresponding values;
all arguments must have an identifier - identifiers can be obtained using
OleAutomation.getIDsOfNamesprivate int invoke(int dispIdMember, int wFlags, Variant[] rgvarg, int[] rgdispidNamedArgs, Variant pVarResult)
public void invokeNoReply(int dispIdMember)
public void invoke(int dispIdMember)
.dispIdMember
- the ID of the method as specified by the IDL of the ActiveX Control; the
value for the ID can be obtained using OleAutomation.getIDsOfNamesSWTException
- public void invokeNoReply(int dispIdMember, Variant[] rgvarg)
public void invoke(int dispIdMember, Variant[] rgvarg)
.dispIdMember
- the ID of the method as specified by the IDL of the ActiveX Control; the
value for the ID can be obtained using OleAutomation.getIDsOfNamesrgvarg
- an array of arguments for the method. All arguments are considered to be
read only unless the Variant is a By Reference Variant type.SWTException
- public void invokeNoReply(int dispIdMember, Variant[] rgvarg, int[] rgdispidNamedArgs)
public void invoke(int dispIdMember, Variant[] rgvarg, int[] rgdispidNamedArgs)
.dispIdMember
- the ID of the method as specified by the IDL of the ActiveX Control; the
value for the ID can be obtained using OleAutomation.getIDsOfNamesrgvarg
- an array of arguments for the method. All arguments are considered to be
read only unless the Variant is a By Reference Variant type.rgdispidNamedArgs
- an array of identifiers for the arguments specified in rgvarg; the
parameter IDs must be in the same order as their corresponding values;
all arguments must have an identifier - identifiers can be obtained using
OleAutomation.getIDsOfNamesSWTException
- private void manageExcepinfo(int hResult, EXCEPINFO excepInfo)
public boolean setProperty(int dispIdMember, Variant rgvarg)
dispIdMember
- the ID of the property as specified by the IDL of the ActiveX Control; the
value for the ID can be obtained using OleAutomation.getIDsOfNamesrgvarg
- the new value of the propertypublic boolean setProperty(int dispIdMember, Variant[] rgvarg)
dispIdMember
- the ID of the property as specified by the IDL of the ActiveX Control; the
value for the ID can be obtained using OleAutomation.getIDsOfNamesrgvarg
- an array of arguments for the method. All arguments are considered to be
read only unless the Variant is a By Reference Variant type.