Microsoft KB Archive/818429

= HOW TO: Upgrade Visual J++ Components to Visual J# .NET =

Article ID: 818429

Article Last Modified on 6/1/2007

-

APPLIES TO


 * Microsoft Visual J# .NET 2003 Standard Edition
 * Microsoft Visual J++ 6.0 Standard Edition

-



SUMMARY
You can compile and run Visual J++ 6.0 Java-language or Microsoft COM components that are used from COM clients.

The steps in the &quot;More Information&quot; section describe how to manually upgrade Java-language or COM components by using a command-line tool. When you upgrade Visual J++ projects in Microsoft Visual Studio .NET, the Microsoft Visual J# Upgrade wizard automates the upgrade process for Visual J++ components.



MORE INFORMATION
Important If the Java-language or COM component was implemented by using the templates that are generated by the JActiveX tool, or your Java-language component implements a type library interface, you must do steps a and b before you do the numbered steps in these instructions:  Use the Tlbimp.exe command-line tool that is included with the Microsoft .NET Framework SDK and Visual Studio .NET to generate managed wrappers from the type library that you used to generate the JActiveX templates. For example, type the following at a command prompt, and then press ENTER:

tlbimp.exe /keyfile:interopKey.snk COMComponent.tlb

 In step 1 of the numbered steps, reference the managed wrapper assemblies that you generated in step a when you compile the Java-language or COM component. For example, type the following at a command prompt, and then press ENTER:

vjc /r:TlbimpGeneratedWrappers



When you upgrade Visual J++ 6.0 Java-language or COM applications to Visual J# .NET, do not manually edit the wrappers that the JActiveX tool generated to add the .NET Framework COM interop attributes or APIs. If you manually edit these wrappers, you may experience unexpected runtime issues. Microsoft does not support the mixing of such attributes as @com and @dll with the .NET Framework COM interop attributes in Visual J++ 6.0. Microsoft strongly discourages this practice both in upgraded Visual J++ Java-language or COM applications and in new applications that are written by using Visual J# .NET.  Compile the Java-language or COM component by using the Visual J# .NET command-line compiler (Vjc.exe). For example, type the following at a command prompt, and then press ENTER to compile the code:

vjc /target:library

  Sign the assembly before you register it by using the /codebase option of the Regasm tool. To sign an assembly, attach the AssemblyKeyFile attribute that is located in the System.Reflection namespace to one of the files in your project, as in the following example: /** @assembly System.Reflection.AssemblyKeyFile(&quot;myKey.snk&quot;) */ where  is a key pair file that the .NET Framework SDK tool Sn.exe generates.  If a COM client gains access to the Java-language or COM component by using the type library that the VJReg.exe tool generates, the COM client uses the dispinterface that is exposed on the component and. The dispIds of the class members are not guaranteed to be the same in Visual J#. If the dispIds of the class members are different from what they were in the Visual J++ version, the existing COM clients may fail. To avoid this problem, verify the following if a type library exists for the Java-language or COM component:  The type library is registered on the computer.</li> The GUID of the type library is specified by using the typelib parameter in the @com.register directive for the component.</li></ol>

In such case, a warning message appears in the Visual J# compiler.</li> Register the generated DLL file or EXE file by using the Regasm.exe command-line tool. (This tool is included with the Microsoft .NET Framework SDK and Visual Studio .NET.) To do this, type the following at a command prompt, and then press ENTER:

Regasm /codebase

</li></ol>

<div class="references_section">