Object CastingCOM objects of one type can be cast to another type using the JComCoerceObjectToAnotherType method of the JComObject class. E.g.
NewType newObj = (NewType) oldObj.JComCoerceObjectToAnotherType( NewType.class );
For typical programming, such coercion will not be required.
If you are unfamiliar with COM, please check the available documentation about the target COM object to see if there is another way to get to the desired interface. Only use this method if the underlying pointers are related and can be cast.
For those familiar with COM, "coerce" in EZ JCom maps to the "QueryInterface" operation of COM.
Threading Models: STA (single-threaded apartment) and MTA (multi-threaded apartment)COM has two types of threading models, STA (single-threaded apartment model) and MTA (multi-threaded apartment model.)
EZ JCom supports both models. In either model, multiple Java threads are supported.
The STA model is the default, and works well with most COM objects. However, some COM objects may work better in MTA mode.
To initialize EZ JCom to use the MTA mode, set the environment variable EZJCOM_MODE to the value MTA. If starting Java from a Command Prompt, this can simply be done by entering the command SET EZJCOM_MODE=MTA before starting Java.
Otherwise, it can be done from the Control Panel by adding a new Environment string.
Creating Objects That Require a Runtime LicenseSome COM objects require a license key before the objects can be created.
For such objects, use the JComCreateLicensedObject method in the JComObject class. There are two overloaded versions, one is for use on a licensed machine, the other takes an actual license string as argument.
Sample usage is:
MyObj myObj = (MyObj) ezjcom.JComObject.JComCreateLicensedObject( MyObj.class, myLicenseString );
Creating Objects from StringsThe JComCreateObjectFromString method in the JComObject class can be used for creating objects from various COM strings such as Monikers, Prog-IDs and GUIDs. This is somewhat like the GetObject of VBA scripts. The class specified to this method must be a COM-interface.
Sample usage is:
IADsOpenDSObject openDsObj = (IADsOpenDSObject) ezjcom.JComObject.JComObjectFromString( IADsOpenDSObject.class, "LDAP:" );
Direct Method and Property AccessEZ JCom generates an API for the COM objects. In addition, it also allows direct access to the methods and properties by name. This is available for "dispatch-based" methods and properties.
To access methods and properties by name, use "JComCallMethod", "JComGetProperty" and "JComSetProperty" in the JComObject class. Any arguments are specified as variants.
DCOM (Districuted COM) supportNOTE: Before using DCOM, please also review the documentation on the EZ JCom Remote Access feature which provides a much simpler remote access mechanism.
Many COM objects can be configured for DCOM operations simply by registry configurations. This will also work for EZ JCom supported COM objects.
In addition, EZ JCom can provide support for DCOM by creating constructors that accept the remote machine name as argument. If you use this version of the constructor, EZ JCom will explicitly request object creation at the remote machine (only.)
By using the DCOM version of the constructor, the initial QueryInterface operations are also optimized by including them in a single method call (therefore doing them all in a single round-trip.)
To enable DCOM support, and select "DCOM Support..." from the additional features page of the Wizard. Then select the checkbox for DCOM support.