public interface Com4jObject
Java interfaces mapped from COM interfaces always derive from this interface directly/indirectly. This interface provides methods that are common to all the COM interfaces.
Modifier and Type | Method and Description |
---|---|
<T> EventCookie |
advise(Class<T> eventInterface,
T receiver)
Subscribes to the given event interface of this object.
|
void |
dispose()
Releases a reference to the wrapped COM object.
|
boolean |
equals(Object o)
Tests the identity of two COM objects.
|
ComThread |
getComThread()
Every Com4jObject has a ComThread that is running handling all the calls to this object.
|
long |
getIUnknownPointer()
QueryInterface to IUnknown and return its raw pointer value.
|
long |
getPointer()
Returns the interface pointer as an integer
|
int |
getPtr()
Deprecated.
64bit unasfe.
|
int |
hashCode()
Hash code consistent with
equals(java.lang.Object) }. |
<T extends Com4jObject> |
is(Class<T> comInterface)
Checks if this COM object implements a given interface.
|
<T extends Com4jObject> |
queryInterface(Class<T> comInterface)
Invokes the queryInterface of the wrapped COM object and attempts
to obtain a different interface of the same object.
|
void |
setName(String name)
You can use this function to set a name to an object.
|
String |
toString()
Prints the raw interface pointer that this object represents.
|
boolean equals(Object o)
This consists of doing IUnknown::QueryInterface on two interfaces and test the bit image of the resulting IUnknown*.
If one COM object implements two interfaces, in Java you see them as two different objects. Thus you cannot rely on == to check if they represent the same COM object.
equals
in class Object
o
- the other Com4jObject
int hashCode()
equals(java.lang.Object)
}.
This method queries the IUnknown* value to the wrapped COM object and returns its pointer bit image as integer.
The net result is that the identity of Com4jObject
is based
on the identity of the underlying COM objects. Two Com4jObject
that are holding different interfaces of the same COM object is
considered "equal".
hashCode
in class Object
Com4jObject
int getPtr()
long getPointer()
long getIUnknownPointer()
ComThread getComThread()
String toString()
void dispose()
Since Java objects tend to live longer in memory until it's GC-ed, and applications have generally no control over when it's GC-ed, calling the dispose method earlier enables applications to dispose the COM objects deterministically.
<T extends Com4jObject> boolean is(Class<T> comInterface)
This is just a convenience method that behaves as follows:
return queryInterface(comInterface)!=null;
T
- the type of the interface class objectcomInterface
- The class object of the Com4J interface<T extends Com4jObject> T queryInterface(Class<T> comInterface)
T
- the type of the interface class objectcomInterface
- the class object of the requested Com4J interface<T> EventCookie advise(Class<T> eventInterface, T receiver)
T
- the type of the eventInterface class object.eventInterface
- The event interface definition. This interface/class
has to have an IID
annotation that designates
the event interface GUID, and also methods annotated with
DISPID
that designates what methods are event methods.
Must not be null.receiver
- The object that receives events.EventCookie.close()
to shut down
the event subscription.ComException
- if a subscription fails.void setName(String name)
name
- the new name of the object.Copyright © 2014. All rights reserved.