INFO: Frequently Ask Questions for Java/COM/DCOM

Last reviewed: January 29, 1998
Article ID: Q168935
The information in this article applies to:
  • Microsoft Win32 Virtual Machine for Java

SUMMARY

This article covers some of the Frequently Asked Questions (FAQ) about Java/COM/DCOM.

For other Java related FAQs search the Web at http://support.microsoft.com/support/ for 'JAVA' and 'FAQ'.

MORE INFORMATION

Q. 1. I am trying to use an ActiveX automation object written in Java (the COMCallingJava sample) from Visual Basic but I keep getting "Out of Memory" errors.

A. This is normally caused by the Operating System not being able to find the Java class file that implements the ActiveX automation server. The class file that implements the Server must be copied to the java classpath (for instance: \windows\java\lib) for OLE object creation to work properly for Java class files. A common example of this is the COMCallingJava sample application supplied with Visual J++. It will work fine when the sample is first built because the CEuclid.class is in the local directory (which the Developer Studio adds to the CLASSPATH before running Internet Explorer). Trying to run the VBDriver Visual Basic sample code supplied in the VBDriver project subdirectory will then fail with the "Out of Memory" error. This can be remedied by copying CEuclid.class to the \windows\java\lib directory. You can also set the output directory in the project build options so that the class file is automatically built in the appropriate classpath directory. This information is also documented in the following Knowledge Base article: Q163720: Getting Out Of Memory Error with COMCallingJava.

Q. 2. Why does Java misinterpret a Boolean value that is returned by a COM object?

A. This is a bug, which has been fixed with the latest Microsoft Virtual Machine for Java. Please follow the link to http://www.microsoft.com/java to download the latest Microsoft Virtual Machine for Java. This version of the Virtual Machine for Java requires Internet Explorer 3.01. This information is also documented in the Microsoft KnowledgeBase article: Q162966: COM Object Returns Incorrect Value for Bool.

Q. 3. Why do I get a "java.lang.ClassFormatError", when I call Automation methods from VJ++ that takes parameters of Pointer type BSTR*, long*?

A. For information on this refer to the Microsoft Knowledge Base article Q165550, BUG: JavaTLB Generates Invalid Classes for MFC Server.

Q. 4. Why do I get an "exception:java.lang.ClassCastException:xl5en32/_ExcelApplication" error, when creating a new _ExcelApplication class and type-casting it to the Application interface?

A. For information on this refer to the Microsoft Knowledge Base article Q169806, PRB: ClassCastException Error When Using Excel Object in Java.

Q. 5. Do Visual J++ applets or applications support ActiveX control containment?

A. Currently, the Microsoft Java class libraries do not support the containment of ActiveX GUI controls. You can't place an ActiveX control that has a user interface or that sources or sinks events directly onto an applet without implementing all of the ActiveX control containment and eventing interfaces yourself. To be clear, you can use ActiveX automation servers from Java and you can write ActiveX automation servers in Java utilizing the Microsoft Java Virtual Machine's ability to expose Java classes as ActiveX objects. You can also have ActiveX controls and Java applets on the same Web page and have them interact (see the OLEControls sample in Visual J++).

Q. 6. How do I use the COMCallingJava sample as a DCOM Server?

A. First you should build the sample and run it as a conventional (InProcess) automation server. Do this by following the instructions outlined in the readme.html that is installed with the sample. More information on how to use this sample via DCOM, can be found in the KnowledgeBase article: Q162164: Using Java Servers and DCOM.

Q. 7. When I try to use JavaReg with the /surrogate switch in order to use my Automation Server written in Java as a DCOM server, the Java console pops up and closes when run on a remote machine and my client application hangs?

A. There are various problems that you may experience when you try to use an Automation Server written in Java as a DCOM server. These can include hanging, timeouts, out of memory errors, interface not found errors, and other errors. These errors are generally caused by not registering the Java COM object properly on both the client and DCOM server machines. There are several known bugs with the javareg DCOM surrogate and the DCOM configuration utility DCOMCNFG that make it difficult to set up Java DCOM servers and clients. This is a bug and you can get more information regarding this and how to setup a Java Automation Server as a DCOM Server in the following Knowledge Base article: Q162164: Using Java Servers and DCOM.

Q. 8. Why do I get an exception when I try and use an OLE Control (a.k.a. OCX) in my Java code?

A. This can be caused by trying to "new" an OLE Control (OCX) from within your Java code and then calling one of the methods of the OLE Control. The Microsoft Java class libraries and Virtual Machine do not currently support the containment of OLE Controls directly in Java applets. An OLE Control requires that numerous interfaces and methods be supported in the "containing" application. This support is currently not implemented. Therefore, your OLE Control is not fully created and returns an OLE error when any method is called. This error gets expressed in Java as a thrown exception. ActiveX automation servers can be used from within your Java code and it is possible to write an OLE Control so that it can be created as a simple automation server that does not require full container support. More information on this can be found in the Microsoft Knowledge Base article: Q146120 - How to Use an OLE Control as an Automation Server.

Q. 9. Why do I get "Failed to Create Object" error message, when trying to instantiate a COM object written in Java?

A. The following is a checklist that provides some of the common causes for this error. Make sure:

    1. The Java class is in the classpath.
    2. Your Java method is declared 'public'.
    3. You need to register the class file (using javareg.exe).
    4. Install the latest Java VM from
       http://www.microsoft.com/java if you are attempting to
       use CreateObject().
    5. Follow the steps in the Visual J++ sample named COMCALLINGJAVA.

Q. 10. Why don't I need to use IDL anymore when creating a Java com object that is used through IDispatch?

A. For information on this refer to the Microsoft Knowledge Base article Q172202, "INFO: Implementing Java Automation Objects using AutoIDispatch."

Q. 11. Is there a way to disable this Auto IDispatch mechanism of the Virtual Machine?

A. You can implement the system interface com.ms.com.NoAutoScripting to disable the Auto IDispatch for all instances of a class.

Q. 12. I get ComFailException:<80020005h>Type Mismatch error, when trying to use the Navigate method of the IWebBrowserApp interface? How do I invoke Internet Explorer from Java and navigate to a URL?

A. The following code snippet illustrates creating a Java Object based on the Microsoft Internet Explorer and calling the Navigate method:

    1. Create a default Java Applet or an Application.
    2. Run JavaTLB on Microsoft Internet Controls.

import com.ms.com.*; import shdocvw.*; public class Navigate {
   IWebBrowserApp testBrowser = null;

   public static void main( String args[] )
   {
      IWebBrowserApp testBrowser = (IWebBrowserApp)new InternetExplorer();
      testBrowser.getApplication();
      testBrowser.putVisible(true);
      Dispatch.call(testBrowser, "Navigate", "http://www.microsoft.com");
   }
}

The Dispatch.call method is documented in the Microsoft SDK for Java Documentation, which can be found at http://www.microsoft.com/java/sdk/x/exten025.htm.

Q. 13. I am able to automate Excel 7.0 from Java, but I am finding the classes and interfaces to be quite different in Excel 8. How do I automate Excel 8.0 from Java?

A. For information on this refer to the Microsoft Knowledge Base article Q169796, HOWTO: Automate Excel from Java.

Q. 14. When I use JavaTLB to generate classes from some COM object libraries, I get an error J5008.

    Should I be concerned?

A. Often, the cause of this warning is that the method uses a type that is not supported in Java. All methods that produce a J5008 warning are omitted from the class file. Note that JavaTLB has been replaced by JavaCOM in the SDK for Java 2.0, preview version.

Q.15. I get a 'java.lang.NoClassDefFoundError: com/ms/com/LicenseMgr' error when I run an applet generated by the Database Wizard for Java?

A. When an applet is run in Internet Explorer and outside of Developer Studio, the applet is not trusted and does not have access to ILicenseMgr. This problem is by design since only trusted applets should have access to the ILicenseMgr. The ILicenseMgr allows the creation of COM objects on the client. To fix the problem, create a CAB file that contains the classes of the applet and digitally sign the CAB with the CodeSign kit. For more information on Cab and Sign technology, look in the 'Cab&Sign' directory on the Visual J++ CD-ROM. For the latest info on CAB technology please refer to 'http://www.microsoft.com/workshop/prog/cab'.

Q. 16. Why does Visual Basic crash when calling a Java Object that has a method that returns a Boolean value?

A. This is a bug with the JavaTLB mapping VT_BOOL to a 4-byte value for vtable mappings. To work around the problem change the return type of the Java function to "short" in the IDL/ODL files with -1 representing TRUE and 0 representing FALSE. This problem has been fixed for JCOM, where it maps VT_B OL to a 2-byte value. You can get JCOM, by installing the SDK for Java 2.0 Preview release from http://www.microsoft.com/java. Note that JavaTLB has been replaced by JCOM in the SDK for Java 2.0 preview version.

Q. 17. When I run a Java Application that calls a COM object like an ATL Server, I get a "NoClassDeffoundError" on the COM object. The error occurs on the line where I create a new COM object in the Java Class?

A. One reason why you may get this error could be related to missing parameter attributes for the methods in the ATL servers IDL file. For Example if you have a method like the one below:

   [id(1), helpstring("method GetString")] HRESULT GetString(BSTR* mystr);

JavaTLB executes fine on this TLB. However when you execute your Java Application that calls this COM object, for example, ISomeInterface m_intf = (ISomeInterface) new CAtlObj, it fails at this line with a "java.lang.NoClassDeffoundError". To fix the problem, change the IDL method to include the [out] attribute. For Example the method looks like the following:

   [id(1), helpstring("method GetString")] HRESULT GetString([out]BSTR*
   strGUID);

So check your methods in the IDL file so that they have the right attributes such as [in],[out],[retval] and so on. Once you've modified the IDL file, rebuild your ATL server, and rerun JavaTLB on the ATL Servers Type Library so that the changes gets reflected.

REFERENCES

For the latest Knowledge Base articles and other support information on Visual J++ and the SDK for Java, see the following page on the Microsoft Technical Support site:

   http://support.microsoft.com/support/visualj/
   http://support.microsoft.com/support/java/

(c) Microsoft Corporation 1997, All Rights Reserved. Contributions by Rafael M. Munoz, Microsoft Corporation
Keywords          : kbcode kberrmsg CmdLnUtils JCOM JVM VJMisc WizardIss kbfaq
Technology        : kbInetDev kbole
Platform          : WINDOWS
Issue type        : kbinfo


================================================================================


THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Last reviewed: January 29, 1998
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.