Microsoft KB Archive/165550

From BetaArchive Wiki

Article ID: 165550

Article Last Modified on 5/12/2007



APPLIES TO

  • Microsoft Visual J++ 1.0 Standard Edition
  • Microsoft Visual J++ 1.1 Standard Edition



This article was previously published under Q165550

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 support information on Visual J++ and the SDK for Java, see the following page on the Microsoft Technical Support site:


Additional query words: bstr* COM

Keywords: kbbug KB165550