Microsoft KB Archive/162966

= FIX: COM Object Returns Incorrect Value for Bool =

Article ID: 162966

Article Last Modified on 5/12/2007

-

APPLIES TO


 * Microsoft Visual J++ 1.0 Standard Edition

-



This article was previously published under Q162966



SYMPTOMS
Calling an Automation method that returns a Boolean value is interpreted incorrectly from Java. If the COM object returns True, Java interprets the return value as False, or if it returns False, then Java interprets the return value as True.



RESOLUTION
The problem has been fixed with the latest Microsoft virtual machine (Microsoft VM). Please follow the link to http://www.microsoft.com/mscorp/java to download the latest Microsoft VM.



STATUS
Microsoft has confirmed this to be a problem in the Microsoft products listed at the beginning of this article. This problem has been fixed in Visual J++ 1.1.



Steps to Reproduce Behavior
 Create a default MFC Automation Server. Using the Class Wizard (OLE Automation Tab) create an automation method that returns a BOOL. Build the project and run it once to register the server. From the command line run JAVATLB /U:T Server.TLB, where Server is your MFC Automation Server. The JAVATLB creates Java class files with information about the COM interfaces and methods. After you have created Java descriptions of COM components, the output window shows two useful types of information, the import statement and the Summary.txt notice. You have to use the command line because Java Type Library Wizard doesn't list MFC Server's Type Library. Create a new Java project.  Create a Java class that uses the services from the MFC Automation Server. The following class illustrates how it uses the Automation Method that returns a BOOL: import server.*   // where server is the MFC Automation Server class javabool { public static void main(String args[]) {   System.out.println("\nStarting test...\n"); IBoolTest btest = (IBoolTest) new BOOLTEST; btest.TestBool;                     //calling the Automation Method System.out.println(btest.TestBool); } }                       </li> Save this .JAVA file and build it.</li> When you run this Java Application, you will notice that Java interprets the Bool value incorrectly.</li></ol>

<div class="references_section">