BUG: JavaTLB Generates Invalid Classes for MFC Server

ID: Q165550

The information in this article applies to:

SYMPTOMS

Using JavaTLB on the TLB files created from MFC ClassWizard generated ODL code generates class files that give the following run-time error:

   ERROR:java.lang.ClassFormatError

CAUSE

This happens only when you add automation methods to your MFC Automation Server (via ClassWizard) that take parameters of pointer type like BSTR*, long*.

RESOLUTION

The workaround is to modify the generated .odl file with [in,out] attributes on the automation methods that take pointer type arguments:

   methods:
   // NOTE - ClassWizard will maintain method information here.

   // Use extreme caution when editing this section.

   //{{AFX_ODL_METHOD(PtrTest)
      [id(1)] void TestBstr([in,out]BSTR* arg1);
      [id(2)] void TestLong([in,out]long* arg1);
   //}}AFX_ODL_METHOD

This allows JavaTlb to generate a valid class file, and the server works as expected when called from Java or Visual Basic.

STATUS

Microsoft has confirmed this to be a problem in the Microsoft products listed at the beginning of this article. We are researching this problem and will post new information here in the Microsoft Knowledge Base as it becomes available.

MORE INFORMATION

Steps to Reproduce Behavior

1. Generate a default MFC AppWizard application, selecting OLE automation

   support.

2. Add an Automation method (using Class Wizard, OLE Automation tab) that
   takes a parameter of type "BSTR *" or "long *".

3. Build the MFC project, and run it once to register.

4. From the command-line, run JAVATLB /U:T on the .TLB file for the

   Server. This creates Java class files with information about the
   COM interfaces and methods. You need to run JAVATLB from the
   command-line, because running Java Type Library wizard doesn't list MFC
   Automation Server's Type Library, from within the IDE.

5. Create a Java project and include the following code to call into OLE
   server:

      import server.*;    //this is generated by running JAVATLB on the
                            server's .TLB.

      class test
      {
        public static void main(String args[])
        {
      System.out.println("\nStarting test...\n");
           IPtrTest ptrTest = (IPtrTest) new PTRTEST();

      String[] strParam = new String[1];
      //int[] intParam = new int[1];
      ptrTest.TestBstr(strParam);   //Calling the automation method
      }
      }

6. Build the Java code and execute the application.

7. If this is the first time you have run the application, Developer Studio

   prompts you for the name of the class.

8. This Java code gives the ClassFormatError as soon as it tries to
   load.

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/ 

Additional query words: bstr* COM

Keywords          : JCOM kbbuglist
Version           : 1.0 1.1
Platform          : WINDOWS
Issue type        : kbbug

Last Reviewed: November 12, 1998