Microsoft KB Archive/165550

= BUG: JavaTLB Generates Invalid Classes for MFC Server =

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 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.



Steps to Reproduce Behavior
 Generate a default MFC AppWizard application, selecting OLE automation support. Add an Automation method (using Class Wizard, OLE Automation tab) that takes a parameter of type "BSTR *" or "long *". Build the MFC project, and run it once to register. 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.  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 }     }

</li> Build the Java code and execute the application.</li> If this is the first time you have run the application, Developer Studio prompts you for the name of the class.</li> This Java code gives the ClassFormatError as soon as it tries to load.</li></ol>

<div class="references_section">